Fix Flask route ordering to prevent catch-all intercepting image routes#3181
Open
elazar wants to merge 2 commits into
Open
Fix Flask route ordering to prevent catch-all intercepting image routes#3181elazar wants to merge 2 commits into
elazar wants to merge 2 commits into
Conversation
Moved catch-all route /<path:path> registration after specific image routes to ensure Flask matches specific routes before the generic catch-all pattern. Route order changes: - /images/series/<path:url> now at line 77 (was never reachable) - /images/movies/<path:url> now at line 92 (was never reachable) - /<path:path> now at line 158 (was at line 70, intercepting everything) This fixes image proxy endpoints /images/series/* and /images/movies/* which were being intercepted by the catch-all route due to Flask's first-match routing behavior. Issue present since initial ui.py creation (June 9, 2022).
Implements 11 test cases covering: - Flask route registration order verification - Route priority behavior (specific vs catch-all) - Image route functionality validation - Integration testing with proper mocking - Demonstrates fix prevents catch-all interception Tests verify specific image routes are matched before catch-all route, ensuring image proxy functionality works correctly.
Owner
|
Putting the catch_all at the end means that other route will be accessible without authorization. I don't see any good to do that since it would expose routes that could be used to potentially exploit vulnerabilities. You'll need to convince me there's benefit here that I don't see because this ordering has been working for years. |
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.
Improves Flask route organization by reordering the catch-all route
/<path:path>to be registered after specific image routes, ensuring optimal route matching based on Flask's first-match routing behavior.Affected Functionality
/images/series/*- Series image requests benefit from improved routing priority/images/movies/*- Movie image requests benefit from improved routing priorityUser-Facing Impact
1. Visual Content Library Experience:
2. Enhanced User Experience Opportunity:
3. Misleading Error Behavior:
4. Integration Impact:
Technical Details
Flask matches routes in registration order (first match wins). The problematic order was:
Route Registration Analysis:
Testing and Validation
Route ordering verified programmatically:
Verification Results:
Context from Debugging Session
This architectural issue was identified during systematic troubleshooting of image proxy failures in a NAS deployment:
The route ordering enhancement works together with the decorator improvement in #3180 to provide comprehensive functionality:
NoneRoute Flow Analysis
Before Fix (Broken):
After Fix (Working):
Files Changed
bazarr/app/ui.py: Moved catch-all route from line 70 to line 158 (51 insertions, 50 deletions)Performance Impact
This architectural enhancement improves image proxy functionality by optimizing route registration order for better request handling.