[PR #6383] [MERGED] Registry: a page's Origin against the site's origin, not its whole URL #6838

Closed
opened 2026-11-03 06:27:48 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6383
Author: @MSedgeMC
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/cm-registry-origin


📝 Commits (1)

  • 10d8d84 Registry: a page's Origin against the site's origin, not its whole URL

📊 Changes

2 files changed (+137 additions, -2 deletions)

View changed files

📝 crates/horizon-mod-registry/src/lib.rs (+76 -2)
📝 crates/horizon-mod-registry/tests/submit.rs (+61 -0)

📄 Description

A submission or a rating is taken only from the site's own pages: its Origin header, then the session cookie and the session's X-CSRF-Token. The README's rule is REGISTRY_PUBLIC_URL's origin.

Horizon compared the Origin header to REGISTRY_PUBLIC_URL as whole strings. A browser's Origin is a scheme, a host and a port and never carries a path, so a public URL with a path (https://playhorizon.dev/mods, the form being a page below the site's root) or another case in its host name refused the site's own page with 403 "send it from the registry's pages" — the message in #6159 — and REGISTRY_PUBLIC_URL pasted with a trailing newline did the same while also spoiling the OAuth callback.

signed_in_here now compares origins: url_origin drops the path from the public URL, the comparison folds case (host names are case-insensitive), and Config::from_env trims the variable before trimming its trailing slash. Another site's page, or a request with no Origin, is still refused, before the sign-in is read.

Proven: cd crates/horizon-mod-registry && cargo test --locked -q — 4 unit and 11 integration tests pass, including a_page_is_known_by_its_origin (path, port, case, another site, no origin) and a_submission_comes_from_the_sites_own_pages (public URL https://playhorizon.test/mods: a page at https://playhorizon.test reaches the sign-in check, 401; a page at https://evil.test and a request with no Origin are 403). The same test against main's lib.rs fails: left: 403, right: 401. cargo clippy --locked --all-targets -- -D warnings and cargo fmt --check are clean.

Not proven: no browser and no deployed service were used: the deployed REGISTRY_PUBLIC_URL and the new site's origin are not known here, so the check that would prove the report's own request is a submission from the redesigned playhorizon.dev/mods/submit once this is out.

Known limit: a site served from a different origin than the configured one is still refused, by design; that case needs REGISTRY_PUBLIC_URL to name the origin the pages are served from.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/6383 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/cm-registry-origin` --- ### 📝 Commits (1) - [`10d8d84`](https://github.com/horizon-rust/horizon/commit/10d8d84295b7160e5cc52efe754eaee1b5142a7c) Registry: a page's Origin against the site's origin, not its whole URL ### 📊 Changes **2 files changed** (+137 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-mod-registry/src/lib.rs` (+76 -2) 📝 `crates/horizon-mod-registry/tests/submit.rs` (+61 -0) </details> ### 📄 Description A submission or a rating is taken only from the site's own pages: its `Origin` header, then the session cookie and the session's `X-CSRF-Token`. The README's rule is `REGISTRY_PUBLIC_URL`'s **origin**. Horizon compared the `Origin` header to `REGISTRY_PUBLIC_URL` as whole strings. A browser's `Origin` is a scheme, a host and a port and never carries a path, so a public URL with a path (`https://playhorizon.dev/mods`, the form being a page below the site's root) or another case in its host name refused the site's own page with 403 "send it from the registry's pages" — the message in #6159 — and `REGISTRY_PUBLIC_URL` pasted with a trailing newline did the same while also spoiling the OAuth callback. `signed_in_here` now compares origins: `url_origin` drops the path from the public URL, the comparison folds case (host names are case-insensitive), and `Config::from_env` trims the variable before trimming its trailing slash. Another site's page, or a request with no `Origin`, is still refused, before the sign-in is read. **Proven:** `cd crates/horizon-mod-registry && cargo test --locked -q` — 4 unit and 11 integration tests pass, including `a_page_is_known_by_its_origin` (path, port, case, another site, no origin) and `a_submission_comes_from_the_sites_own_pages` (public URL `https://playhorizon.test/mods`: a page at `https://playhorizon.test` reaches the sign-in check, 401; a page at `https://evil.test` and a request with no `Origin` are 403). The same test against main's `lib.rs` fails: `left: 403, right: 401`. `cargo clippy --locked --all-targets -- -D warnings` and `cargo fmt --check` are clean. **Not proven:** no browser and no deployed service were used: the deployed `REGISTRY_PUBLIC_URL` and the new site's origin are not known here, so the check that would prove the report's own request is a submission from the redesigned `playhorizon.dev/mods/submit` once this is out. Known limit: a site served from a different origin than the configured one is still refused, by design; that case needs `REGISTRY_PUBLIC_URL` to name the origin the pages are served from. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:27:48 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6838
No description provided.