Skip to content

fix(events): resolve same-scheme redirects without slashes, and send Allow on 405 - #754

Merged
JuroOravec merged 4 commits into
mainfrom
fix/events-redirect-and-allow
Nov 18, 2026
Merged

JuroOravec merged 4 commits into
mainfrom
fix/events-redirect-and-allow

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

What changed

  • Redirects without JavaScript. To the browser, actions.Redirect("http:next") on an http: page (or "https:next" on an https: page) is a relative URL. Citry's browser code (location.assign) resolves it against the page. The no-JavaScript form path sent it on unchanged, so the browser read the 303 Location against the handler's URL and usually landed on a "not found" page. _resolve_redirect_url now resolves such a URL against a same-host Referer, like any other relative URL. A URL with a / or \ right after the colon, or a page with the other scheme, still goes out unchanged, because neither depends on the page.
  • Allow on 405. The ASGI and WSGI adapters answered a method the route does not accept with a 405 and no Allow header, which HTTP requires. They now send one, built by a new shared helper, route_allowed_methods. Django's 405 uses the same list, so it now names HEAD wherever the route accepts GET.
  • Handler discovery skips ViewEvents. Handler discovery and config resolution now skip Citry's ViewEvents base class, as they already skip Events. ViewEvents defines no public method today, so no behavior changes now. A public helper added to it later will not become a handler on every subclass.
  • Tests for tricky URL forms. New tests fix the expected Location for URL forms that browsers and URL parsers read with different hosts: a backslash in or after the authority, credentials, a scheme without //, escaped or full-width slashes. The server does not check hosts. Each Location keeps the URL the app returned, with non-ASCII characters percent-encoded, or resolves it against the page when the browser would read it as relative.
  • docs/design/trust_boundaries.md rows (Redirect, handler name, every adapter), a sentence in the extension routes docs, and two Fixes lines under ## Unreleased in CHANGELOG.md.

Checks

  • Focused pytest, run with the published citry-core 2.1.1 wheel: 732 passed. The files were the redirect, scheme reader, events routes, route path rules, ViewEvents, Django, host adapter and host parity suites.
  • The new tests fail on main for the expected reasons: the old Location, no Allow header, no HEAD in the list, and the helper becoming a handler.
  • Node's URL class follows the URL standard that browsers use. Resolving each Location against the handler URL reached the same address as resolving the original URL against the page: 100 cases from the author and 500 from the reviewer, with no differences.
  • ruff check and ruff format (0.14.13, the locked version): clean. mypy on the touched modules, default platform and --platform linux: clean. The trust rows validator passes.
  • An independent review covered security (navigation, responses Citry serves), the advisory classes (open redirect, header injection, HTTP cache, method and CSRF confusion) and the prose. It found no hole. Its findings are applied: wording, tests for a Referer with no path or with a port, the no-Referer warning, and one trust row cite.

Versioning

Nothing the 1.x promise covers breaks. The redirect change makes the documented rule hold ("relative to the page the visitor is on, with or without JavaScript"). The Allow header is new, and Django's Allow value gains HEAD. The new helpers live in internal modules. A patch release is enough.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED

JuroOravec and others added 4 commits November 18, 2026 05:20
…llow on 405

- Without JavaScript, `Redirect("http:next")` on an `http:` page (and
  `"https:next"` on an `https:` page) now resolves against the page, as
  the browser runtime does, instead of against the handler URL.
- The ASGI and WSGI adapters send an `Allow` header with a 405; every
  adapter's list names `HEAD` where the route accepts `GET`.
- Handler discovery skips the `ViewEvents` base class as it skips
  `Events`, so a public helper added to it never becomes a handler.
- Tests lock the Location for URL forms that URL parsers read with
  different hosts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
httpx2 builds the follow-up request from the Location header even with
follow_redirects=False, and its URL parser rejects a scheme with no host
and no leading "/" (such as "http:next"). Seven redirect tests sent such
values on purpose and failed in CI. They now drive the mounted ASGI app
directly and compare the status and Location the server wrote.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
Resolve the conflicts in CHANGELOG.md (keep the main entries and this
branch's two entries under one Unreleased Fixes list) and in
docs/design/trust_boundaries.md (merge the Redirect and handler-name
rows: main's refreshed text plus this branch's resolver, ViewEvents
framework-base facts and updated line numbers).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
@JuroOravec
JuroOravec merged commit 8fd2e32 into main Nov 18, 2026
33 checks passed
@JuroOravec
JuroOravec deleted the fix/events-redirect-and-allow branch November 18, 2026 11:17
JuroOravec added a commit that referenced this pull request Nov 18, 2026
)

* docs(security): add review records for #754, #755, #756, #757 and #759

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED

* docs(security): apply review findings to the 1.0.2 hardening records

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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