Skip to content

feat(users): use an allowlisted request origin for account email links - #1151

Merged
antosubash merged 4 commits into
mainfrom
claude/project-thread-lg6bda-base-url
Nov 29, 2026
Merged

antosubash merged 4 commits into
mainfrom
claude/project-thread-lg6bda-base-url

Conversation

@antosubash

@antosubash antosubash commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Requested by Anto · project thread

Summary

Split 2 of 3 from #1137: the actual fix for #1126, with the CIDR change and the Doctor hook removed. Based on main; the Doctor PR stacks on this one.

  • Behaviour change (users: account emails fall back to the request origin when its host is allowlisted #1126): with neither users.base_url nor host.public_base_url / SM_PUBLIC_BASE_URL set, password-reset, verification and invitation emails link to the current request's origin, but only if its host matches host.forwarded_host_allowlist. Plain http is accepted only from a trusted proxy or for a loopback host. Otherwise the mail is skipped with the existing ERROR and the public response stays generic.
  • Precedence: users.base_url → host.public_base_url → allowlisted request origin → skip. Sends without a request still require a configured origin.
  • New trusted_request_origin(request) in simple_module_hosting.pipeline.public_urls.
  • The public Mailer protocol keeps its signatures; link_origin goes only to mailers whose send methods accept it as a keyword.

New relative to #1137: the shared host parser change (fullmatch, port ≤ 65535, bracketed IPv6) also changes ForwardedHostMiddleware, and #1137 neither documented nor tested that. This PR adds middleware tests for bracketed IPv6 and invalid IPv6/port values, a CHANGELOG line and a note in the middleware docs. TrustedPeers parsing is unchanged here (see the CIDR PR).

Fixes #1126. Follow-up: #1136.

Test plan

  • framework/hosting/tests/pipeline + modules/users/tests: 1666 passed
  • Python lint targets of make lint (ruff, ty, metadata, locales, doc paths, i18n freshness, file size, sleeps, hardcoded strings, CI parity). JS targets not run in this sandbox; this PR has no JS changes
  • With no origin configured and your host on host.forwarded_host_allowlist, request a password reset: the mail links to your host
  • With a forged Host, the same request returns the same response and sends nothing
  • CI green

Generated by Claude Code


Also folds in #1136 (carries the allowlisted request origin via a scoped ContextVar to the deferred invite companion verification email for HTTP single & bulk invites while keeping background/CLI creates requiring a configured origin) and hardens proxied HTTP detection to require an explicit single-value X-Forwarded-Proto: http.

Closes #1126
Closes #1136

When neither users.base_url nor host.public_base_url is set, password-reset,
verification and invitation emails link to the current request's origin,
but only if its host matches host.forwarded_host_allowlist (the matcher
ForwardedHostMiddleware uses, applied after proxy handling). Plain http is
accepted only from a trusted proxy or for a loopback host. Otherwise the
mail is still skipped with an ERROR and the public response stays generic.
Sends with no request keep requiring a configured origin.

The shared host parser now uses fullmatch, rejects ports above 65535 and
accepts bracketed IPv6, which ForwardedHostMiddleware also picks up; that
is covered by new middleware tests.

Split out of #1137 (the CIDR fix and the Doctor hook are separate PRs).

Fixes #1126

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXHA3ZEgbUuM5mzoeC4DTw
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 17f42d8
Status: ✅  Deploy successful!
Preview URL: https://ad7406b7.simple-module-python.pages.dev
Branch Preview URL: https://claude-project-thread-lg6bda-a9fq.simple-module-python.pages.dev

View logs

…-lg6bda-base-url

# Conflicts:
#	CHANGELOG.md
#	docs/modules/users.md
#	modules/users/users/accounts/manager.py
#	modules/users/users/admin/api.py
#	modules/users/users/admin/views.py
#	modules/users/users/invites/resend.py
@antosubash
antosubash marked this pull request as ready for review November 29, 2026 08:55
@antosubash antosubash added the shipped /ship passed on the head commit label Nov 29, 2026
@antosubash

Copy link
Copy Markdown
Owner Author

/ship passed on 17f42d8

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-29T08:59:26.426691Z 17f42d8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@antosubash
antosubash merged commit 0cb4f26 into main Nov 29, 2026
22 checks passed
@antosubash
antosubash deleted the claude/project-thread-lg6bda-base-url branch November 29, 2026 09:00
antosubash pushed a commit that referenced this pull request Nov 29, 2026
#1151 merged as a squash, so the old fallback commit on this branch is
resolved to main's versions. AGENTS.md moved its lifecycle section to
.agents/rules/architecture.md, so the doctor_diagnostics mention moves
there. The users menu URL and icon constants move to users.core.constants
to keep users/module.py under the 300-line cap with the new hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXHA3ZEgbUuM5mzoeC4DTw
antosubash pushed a commit that referenced this pull request Nov 29, 2026
The previous merge commit lost its second parent; this records origin/main as a parent without changing files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXHA3ZEgbUuM5mzoeC4DTw
antosubash added a commit that referenced this pull request Nov 29, 2026
…eck (#1152)

* feat(users): use an allowlisted request origin for account email links

When neither users.base_url nor host.public_base_url is set, password-reset,
verification and invitation emails link to the current request's origin,
but only if its host matches host.forwarded_host_allowlist (the matcher
ForwardedHostMiddleware uses, applied after proxy handling). Plain http is
accepted only from a trusted proxy or for a loopback host. Otherwise the
mail is still skipped with an ERROR and the public response stays generic.
Sends with no request keep requiring a configured origin.

The shared host parser now uses fullmatch, rejects ports above 65535 and
accepts bracketed IPv6, which ForwardedHostMiddleware also picks up; that
is covered by new middleware tests.

Split out of #1137 (the CIDR fix and the Doctor hook are separate PRs).

Fixes #1126

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXHA3ZEgbUuM5mzoeC4DTw

* feat(core): ModuleBase.doctor_diagnostics hook; users SM035 origin check

Modules can add read-only findings to make doctor / smpy doctor through
the new ModuleBase.doctor_diagnostics(database_url) override (never run at
boot). Doctor resolves the database URL once and passes it to every hook.
A hook that raises or returns something other than Diagnostic objects
becomes SM036 (ERROR), without its exception text, and Doctor continues.

The users module uses the hook for SM035: a WARNING when users.base_url,
host.public_base_url and host.forwarded_host_allowlist are all empty, so
account emails have no origin.

Framework-level tests cover the hook without the users module.

Split out of #1137; stacked on the account email origin PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXHA3ZEgbUuM5mzoeC4DTw

* feat(users): carry allowlisted request origin to invite verification mail (#1136)

* fix(users): align SM035 origin and allowlist checks with runtime hydration

* Merge main into the Doctor hook branch after #1151

#1151 merged as a squash, so the old fallback commit on this branch is
resolved to main's versions. AGENTS.md moved its lifecycle section to
.agents/rules/architecture.md, so the doctor_diagnostics mention moves
there. The users menu URL and icon constants move to users.core.constants
to keep users/module.py under the 300-line cap with the new hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FXHA3ZEgbUuM5mzoeC4DTw

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shipped /ship passed on the head commit

Projects

None yet

2 participants