Fix 403 handling and add login links to prevent nginx 404 fallthrough #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where protected pages were showing 404 errors instead of proper 403 access denied pages with login links.
Problem
Users reported that certain protected URLs were redirecting to 404 instead of showing a 403 forbidden page:
/wiki/Accueil/history/w/index.php?title=Page&oldid=12742/wiki/Special:WhatLinksHere/PageThe extension was correctly detecting and blocking these requests, but the nginx configuration was falling through to the catch-all
location / { return 404; }rule instead of serving the 403 response.Root Cause
The
denyAccess()method was setting the HTTP 403 status code but not properly preparing the OutputPage for a complete response. This caused MediaWiki to continue processing in an unexpected way, leading nginx to not recognize it as a valid 403 response.Solution
1. Improved 403 handling:
$output->clearHTML()to ensure clean output$output->returnToMain()to provide proper page structure and navigation2. Added login links:
[[Special:UserLogin|log in]]links3. Added test coverage:
denyAccess()calls all the required OutputPage methodsTechnical Details
The key changes ensure the OutputPage is completely prepared:
The
returnToMain()method is crucial as it adds standard MediaWiki page elements that nginx expects in a proper response, preventing the fallthrough to the 404 rule.Changes Made
includes/Hooks.php)i18n/en.json,i18n/de.json)denyAccessmethod behavior.gitignoreandcomposer.jsonThe changes are minimal and maintain full backward compatibility while addressing both the 404 issue and the missing login link request.
Fixes #5.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/global-state/zipball/b6781316bdcd28260904e7cc18ec983d0d2ef4f6/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/539c6691e0623af6dc6f9c20384c120f963465a0/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c/usr/bin/php8.3 -n -c /tmp/kg6UHI /usr/bin/composer require --dev phpunit/phpunit ^9.0 --no-interaction(http block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.