Skip to content

fix: accept only a serialized origin in the cross-site check (BootUI 2.6.0) - #371

Draft
ffroliva wants to merge 21 commits into
mainfrom
fix/0.11.0-s1-serialized-origin
Draft

ffroliva wants to merge 21 commits into
mainfrom
fix/0.11.0-s1-serialized-origin

Conversation

@ffroliva

@ffroliva ffroliva commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Summary

Tasks 1.1 and 1.2 of the 0.11.0 plan (#367), row S1 of the BootUI 2.6.0 delta: the cross-site check accepts only a
serialized origin and refuses same-site or malformed browser metadata on a write.

  • src/sharpit/engine/guard.py
    • _parse_origin accepts only scheme://host[:port] with http or https, as BootUI 2.6.0's
      LocalhostGuard.extractOriginHost does: no path (a trailing slash included), query, fragment, userinfo, control
      character, trailing colon, port above 65535 or other scheme; the value is not trimmed; null stays opaque.
    • An Origin or Host port longer than five digits is refused before int(). Before this change such a port raised
      ValueError (Python limits int() to 4300 digits) and the request ended in HTTP 500.
    • A present but empty Origin is cross-site; only an absent header counts as absent.
    • On a write, Sec-Fetch-Site must be same-origin or none (ASCII only, so a Unicode look-alike never passes).
    • The Origin is parsed once per request.
  • sharpit keeps checking Origin and Sec-Fetch-Site: cross-site on every method, and on API paths a present Origin
    must equal the request's own origin, port included, whatever Sec-Fetch-Site says. Both are recorded deviations
    (docs/reference/matrix-updates/0.11.0-guard.tsv, spec §14 rows 8 and 35).
  • SECURITY.md and docs/reference/BOOTUI-CONTRACT-MVP.md describe the new rule.

Behaviour change: a trailing-slash Origin and an empty Origin on a GET are now refused. Browsers send neither.

Red evidence

Every new test below was run against the base source (b5283506, src/ unchanged, the new tests in place):
23 failures, each an assertion under tests/ except the two FastAPI oversized-port tests, which fail with the HTTP 500
they name.

Defect Test Red on the base
non-serialized origins accepted (path, space, scheme, port range, IPv6 trailing colon) tests/engine/test_guard.py::test_serialized_origin_rejects_what_2_6_0_rejects FAILED (per row)
trailing-slash origin accepted tests/engine/test_guard.py::test_rejects_non_serialized_origin_with_trailing_slash FAILED
blank origin treated as absent tests/engine/test_guard.py::test_a_blank_origin_is_present_and_cross_site FAILED
same-site and unknown metadata accepted on a write tests/engine/test_guard.py::test_same_site_and_unknown_fetch_metadata_refuse_a_write FAILED
Unicode look-alike of same-origin accepted tests/engine/test_guard.py::test_fetch_metadata_allow_list_is_ascii_only FAILED
origin-only write with another scheme or port accepted tests/engine/test_guard.py::test_origin_only_write_must_match_scheme_and_effective_port FAILED
browser metadata makes a malformed origin acceptable tests/engine/test_guard.py::test_browser_metadata_never_makes_malformed_or_foreign_origins_acceptable FAILED
oversized Origin port gives HTTP 500 tests/fastapi/test_cross_site_origin.py::test_oversized_origin_port_is_cross_site_without_error FAILED (500)
oversized Host port gives HTTP 500 tests/fastapi/test_cross_site_origin.py::test_oversized_host_port_is_cross_site_without_error FAILED (500)
empty Origin served by the FastAPI adapter tests/fastapi/test_cross_site_origin.py::test_empty_origin_header_is_refused_by_the_fastapi_adapter FAILED (200)
empty Origin served by the console tests/engine/test_console_contract.py::test_empty_origin_header_is_refused_by_the_console FAILED
the parser raises on hostile input tests/fuzz/test_trust_boundary_fuzz.py::test_parse_origin_never_raises FAILED (ValueError)

Other new tests pin behaviour that already held and must keep holding (the API-path full-origin rule, safe-method
scope, IPv6 and mixed-case origins).

Review findings

Three independent reviews found no fail-open path and no request that ends in an error. Their findings were test and
wording quality, addressed in the last commit:

Finding Change
loops and compound asserts hide which case failed parametrized; one condition per assert
a docstring called a BootUI rule a deviation only the real deviations are named
the Origin was parsed twice on API paths parsed once; same decisions by construction
tests without a source citation # derived: comments

Verification

uv run ruff check, uv run ruff format --check, uv run pyright (0 errors);
uv run pytest -q -n 4 tests/engine tests/fastapi/test_cross_site_origin.py tests/fuzz tests/test_code_shape.py tests/docs
(7161 passed, 16 skipped). The three overhead-budget tests pass when run alone (-n 0).

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
… file

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
…e protocol

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
The Origin header is parsed as scheme://host[:port] with an http or https scheme, as BootUI 2.6.0 does: a path (a trailing slash included), query, fragment, userinfo, control character, trailing colon, unsupported scheme or a port above 65535 makes the origin unreadable, and an unreadable origin is cross-site. The value is no longer trimmed.\n\nA port of more than five digits is refused before int() converts it, in the origin and in the request's own Host, so a very long port is a cross-site refusal and no longer an unhandled ValueError. Adds a property test of the origin parser.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
…UI 2.6.0)

A write that carries Sec-Fetch-Site must send same-origin or none (ASCII, case-insensitive); same-site, cross-site, an empty value and any unknown value are refused. A present but empty Origin header is an unreadable origin and is cross-site, no longer read as absent. A same-site navigation GET still loads the shell, and an API path still requires the request's own scheme, host and port. A request whose own origin cannot be formed stays cross-site where that comparison applies.\n\nDocuments the rule in SECURITY.md and the BootUI contract note, and records the deviations in the 0.11.0 guard matrix fragment.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>

# Conflicts:
#	tests/fuzz/test_trust_boundary_fuzz.py

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant