fix(security): reliably set Referrer-Policy: same-origin on the login page - #62490
fix(security): reliably set Referrer-Policy: same-origin on the login page#62490Narita-1095305 wants to merge 2 commits into
Conversation
… page
The <If> matched %{REQUEST_URI} against m#/login$#, which sees the
post-rewrite URI, so with the front-controller rewrite active /login fell
through to the <Else> branch and got Referrer-Policy: no-referrer. It also
failed for /login/ and /index.php/login. Match %{THE_REQUEST} instead so the
login page reliably gets same-origin.
Fixes nextcloud#60464
Signed-off-by: Rikiya Narita <b2560305@planet.kanazawa-it.ac.jp>
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
Summary
The login page relies on the security-headers block in the root
.htaccessto sendReferrer-Policy: same-origin(every other path getsno-referrer):%{REQUEST_URI}inside<If>is evaluated against the post-rewrite URI. Once the front-controller rewrite installed byocc maintenance:update:htaccessis active (RewriteRule . index.php [PT,E=PATH_INFO:$1], added whenhtaccess.RewriteBaseis set), the URI the expression sees is no longer/login, so the match fails and the request falls through to the<Else>branch — the login page ends up withReferrer-Policy: no-referrerinstead ofsame-origin.The same
m#/login$#match also fails, independently of any rewrite, for:/login/(trailing slash — the exact form in the issue title), and/index.php/login.There is no PHP-layer fallback:
LoginControlleronly injects an HTML<meta name="referrer">tag, and<Else>'sHeader always setwould override any header the PHP layer tried to set — so this must be fixed in.htaccess.Fix
Match against
%{THE_REQUEST}— the original request line, which is not affected by mod_rewrite — and allow an optionalindex.php/prefix, an optional trailing slash, and a following query string:Verification
Reproduced and verified against Apache 2.4 (mod_headers + mod_rewrite) with the current
.htaccessplus the front-controller rewrite (i.e. the reporter's configuration), using a backend that sets no Referrer-Policy of its own:/loginno-referrer❌same-origin✅/login/no-referrer❌same-origin✅/login?redirect_url=…no-referrer❌same-origin✅/index.php/loginno-referrer❌same-origin✅/settings,/apps/files,/no-referrer✅no-referrer✅/relogin,/apps/login(no false match)no-referrer✅no-referrer✅apachectl -treportsSyntax OKwith the change.Checklist
.htaccess/Apache header behavior is not covered by the PHP test suite (the existingSecurityHeaderssetup-check only probes theheartbeatroute and accepts any valid Referrer-Policy value). Verified manually against Apache as shown above; happy to add coverage if maintainers can point to a suitable harness.AI (if applicable)