File: setSameSiteMultiAttribute.py

package info (click to toggle)
firefox-esr 91.13.0esr-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,375,652 kB
  • sloc: cpp: 5,762,054; javascript: 5,481,714; ansic: 3,121,191; python: 851,492; asm: 331,172; xml: 178,949; java: 155,554; sh: 63,704; makefile: 20,127; perl: 12,825; yacc: 4,583; cs: 3,846; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; php: 436; lisp: 260; awk: 231; ruby: 103; sed: 53; sql: 46; csh: 45
file content (60 lines) | stat: -rw-r--r-- 3,460 bytes parent folder | download | duplicates (25)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from cookies.resources.helpers import makeCookieHeader, setNoCacheAndCORSHeaders

from wptserve.utils import isomorphic_encode

def main(request, response):
    """Respond to `/cookie/set/samesite?{value}` by setting the following combination of cookies:
    1. `samesite_unsupported={value};SameSite=Unsupported;path=/;Secure`
    2. `samesite_unsupported_none={value};SameSite=Unsupported;SameSite=None;path=/;Secure`
    3. `samesite_unsupported_lax={value};SameSite=Unsupported;SameSite=Lax;path=/`
    4. `samesite_unsupported_strict={value};SameSite=Unsupported;SameSite=Strict;path=/`
    5. `samesite_none_unsupported={value};SameSite=None;SameSite=Unsupported;path=/;Secure`
    6. `samesite_lax_unsupported={value};SameSite=Lax;SameSite=Unsupported;path=/;Secure`
    7. `samesite_strict_unsupported={value};SameSite=Strict;SameSite=Unsupported;path=/;Secure`
    8. `samesite_lax_none={value};SameSite=Lax;SameSite=None;path=/;Secure`
    9. `samesite_lax_strict={value};SameSite=Lax;SameSite=Strict;path=/`
    10. `samesite_strict_lax={value};SameSite=Strict;SameSite=Lax;path=/`
    Then navigate to a page that will post a message back to the opener with the set cookies"""
    headers = setNoCacheAndCORSHeaders(request, response)
    value = isomorphic_encode(request.url_parts.query)

    headers.append((b"Content-Type", b"text/html; charset=utf-8"))
    # Unknown value; single attribute
    headers.append(makeCookieHeader(
        b"samesite_unsupported", value, {b"SameSite":b"Unsupported", b"path":b"/", b"Secure":b""}))

    # Multiple attributes; first attribute unknown
    headers.append(makeCookieHeader(
        b"samesite_unsupported_none", value, {b"SameSite":b"Unsupported", b"SameSite":b"None", b"path":b"/", b"Secure":b""}))
    headers.append(makeCookieHeader(
        b"samesite_unsupported_lax", value, {b"SameSite":b"Unsupported", b"SameSite":b"Lax", b"path":b"/"}))
    headers.append(makeCookieHeader(
        b"samesite_unsupported_strict", value, {b"SameSite":b"Unsupported", b"SameSite":b"Strict", b"path":b"/"}))

    # Multiple attributes; second attribute unknown
    headers.append(makeCookieHeader(
        b"samesite_none_unsupported", value, {b"SameSite":b"None", b"SameSite":b"Unsupported", b"path":b"/", b"Secure":b""}))
    headers.append(makeCookieHeader(
        b"samesite_lax_unsupported", value, {b"SameSite":b"Lax", b"SameSite":b"Unsupported", b"path":b"/", b"Secure":b""}))
    headers.append(makeCookieHeader(
        b"samesite_strict_unsupported", value, {b"SameSite":b"Strict", b"SameSite":b"Unsupported", b"path":b"/", b"Secure":b""}))

    # Multiple attributes; both known
    headers.append(makeCookieHeader(
        b"samesite_lax_none", value, {b"SameSite":b"Lax", b"SameSite":b"None", b"path":b"/", b"Secure":b""}))
    headers.append(makeCookieHeader(
        b"samesite_lax_strict", value, {b"SameSite":b"Lax", b"SameSite":b"Strict", b"path":b"/"}))
    headers.append(makeCookieHeader(
        b"samesite_strict_lax", value, {b"SameSite":b"Strict", b"SameSite":b"Lax", b"path":b"/"}))

    document = b"""
<!DOCTYPE html>
<script>
  // A same-site navigation, which should attach all cookies including SameSite ones.
  // This is necessary because this page may have been reached via a cross-site navigation, so
  // we might not have access to some SameSite cookies from here.
  window.location = "../samesite/resources/echo-cookies.html";
</script>
"""

    return headers, document