Log Origin and Sec-Fetch-Site when a session write is refused as cross-origin

Open Beginner friendly
#34 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, python

Research direction

Start in server/orcaster_server/deps.py at the require_session Origin check; read the existing tests for that dependency and the admin error handler in server/orcaster_server/main.py:636-651. Add the requested caplog coverage for an htmx cross-origin POST, then update the Unreleased section of the changelog. Done means the test verifies the warning fields and absence of credentials, while the response remains 403 with the same detail and no HX-Redirect.

Written by the indexing model from the issue text.

Description

enhancement P3 server

Problem

require_session refuses a cookie-authenticated write (POST, PUT, PATCH, DELETE) when the Origin check fails. It raises 403 with the detail cross-origin request refused (server/orcaster_server/deps.py:72).

The admin error handler already passes this 403 through instead of redirecting to the login page (server/orcaster_server/main.py:636-651). The user now sees an error, not a login loop.

The application logger still writes nothing when it refuses the request. Only the uvicorn access log shows the 403, without the header values. The usual causes are a WEBAUTHN_ORIGIN that does not match the public URL, or a reverse proxy that rewrites or strips Origin. An operator who sees the 403 cannot tell from the server log which header value was received or what was expected.

Steps to reproduce

  1. Start the server with WEBAUTHN_ORIGIN set to a value that differs from the URL used in the browser.
  2. Sign in to the dashboard and do any action that sends a POST.
  3. The browser shows the 403. The application log has no line about it.

Proposed change

  • In require_session, when the Origin check fails, log one WARNING with the received Origin header, the received Sec-Fetch-Site header, the request method and the path.
  • Do not log cookies, tokens or other headers. Cap the logged header length.
  • Add a test that sends a cross-origin POST with HX-Request: true. Assert the response is 403 without HX-Redirect, and that the WARNING is logged (caplog).

Acceptance criteria

  • A refused cross-origin write logs one WARNING with the received Origin and Sec-Fetch-Site.
  • The log line contains no cookie, token or other credential.
  • The response is unchanged: status 403 and the same detail. Existing clients and the /api/v1 error model keep working.
  • A test covers the htmx case (HX-Request: true) and checks the log record.
  • CHANGELOG entry under Unreleased.

Open questions

  • Should AuthOriginCheckMiddleware (server/orcaster_server/auth/origin.py:108) log the same way for /auth/* routes?
  • Should the log line also include the expected origin (the configured WEBAUTHN_ORIGIN)?
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.