fix(nginx): return JSON errors for unmatched api/feed/backup paths - #110
Open
bakerboy448 wants to merge 1 commit into
Open
fix(nginx): return JSON errors for unmatched api/feed/backup paths#110bakerboy448 wants to merge 1 commit into
bakerboy448 wants to merge 1 commit into
Conversation
A bare or malformed /api, /feed, or /backup path fell through to the try_files directory handler and got an HTML 301/404, which breaks JSON API clients (they fail parsing with 'invalid character <'). Add location blocks that return a 404 JSON body for those unmatched paths so clients always get JSON. Valid /<consumer>/api/... routes are matched earlier and are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem: a bare or malformed
/api,/feed, or/backuppath (no consumer prefix / no endpoint) falls throughtry_files $uri $uri/and nginx returns an HTML 301 trailing-slash redirect (or default HTML 404). JSON API clients then fail withinvalid character '<'instead of getting a parseable error. Hit in practice by arr automation repointed at starrproxy.Fix: add
locationblocks that return404 {"error":"not found"}withapplication/jsonfor those unmatchedapi|feed|backuppaths. Valid/<consumer>/api/...(and feed/backup) routes are matched by the earlier regex locations and are unaffected;/health, PHP, and static handling are unchanged.nginx-only change; validated with
git diff --check(no livenginx -tavailable in the authoring env).