fix(#17): Auto-fix (multi-mode) (multi-mode flow) - #34
Conversation
|
|
||
| def _upgrade_hsts_redirect(self, resp: Response, url: str) -> str: | ||
| parsed_response = urlparse(resp.url) | ||
| parsed_redirect = urlparse(url) |
There was a problem hiding this comment.
🔗 compatibility · 🟠 Major
Hostname-only HSTS cache can incorrectly rewrite redirects on other ports
_update_hsts_hosts() stores only hostname.lower() in the session cache, and _upgrade_hsts_redirect() later upgrades any http:// redirect whose hostname matches that cached value. Because the rewritten URL preserves the original port, a response from https://example.com that advertises HSTS will also cause a later redirect to http://example.com:8080/... to be rewritten to https://example.com:8080/.... The diff shows no port check or origin scoping in either method (src/requests/sessions.py lines 134-164), so this changes behavior for same-host services on different ports and can break redirects to endpoints that do not serve TLS on that port. Please scope the cache/match to the full origin semantics you intend (for example, include the effective port in the cache key or explicitly gate upgrades to default HTTP/HTTPS ports), and add tests proving the chosen compatibility behavior.
P2 · Impact high (4/5) · Confidence high
🤖 Prompt for AI agents
Adjust the HSTS tracking and redirect-upgrade logic so it does not over-apply to same-host redirects on unrelated ports, then add tests covering default-port and explicit cross-port redirect cases.
🔒 Secure confirmation — opens an authenticated page; the fix is attributed to you. Or reply @aziron fix finding:hsts-port-scope-overreach
| assert r.history[0].request.headers["Authorization"] | ||
| assert "Authorization" not in r.request.headers | ||
|
|
||
| def test_hsts_redirect_upgrades_http_location(self): |
There was a problem hiding this comment.
🧪 test · 🟡 Moderate
Redirect rewrite tests do not cover the new cross-port behavior
This new test only covers the happy path https://example.com -> http://example.com/... upgrade. The production change introduces stateful host-based rewriting in SessionRedirectMixin (src/requests/sessions.py lines 134-164, 261-262), but there is no regression test for an explicit-port redirect such as http://example.com:8080/..., nor a negative case where no HSTS header is present. Without those cases, the current suite would not catch the compatibility issue where hostname-only matching upgrades redirects on other ports. Please extend this test area with cross-port and no-HSTS cases so the intended redirect contract is pinned down.
P3 · Impact medium (3/5) · Confidence high
🤖 Prompt for AI agents
Add redirect resolution tests for explicit-port URLs and for responses without Strict-Transport-Security, asserting the intended rewrite/no-rewrite behavior.
🔒 Secure confirmation — opens an authenticated page; the fix is attributed to you. Or reply @aziron fix finding:missing-cross-port-test
🔍 Aziron Pulse Review
This PR adds session-level HSTS tracking so redirects from an HTTPS response to an HTTP Location on the same host are upgraded back to HTTPS. The core mechanism is plausible, but it currently over-applies HSTS to all ports on a host and lacks tests covering that compatibility edge, which can change redirect behavior incorrectly for services running on different ports. Confidence Score: 2/5 The diff is small and the control flow change is clear, so the main behavioral implications are visible from the provided code. Confidence is not high because only bounded excerpts are available and there is no broader project context or upstream issue statement clarifying the intended HSTS scope. 💬 Pre-merge checks · ✅ 1 · ❌ 3❌ Failed checks
✅ Passed checks
📝 WalkthroughEngineering ReviewWhat changed: In Correctness: The added flow is internally consistent for the covered case: the response URL is parsed, a host is remembered only when the response scheme is HTTPS and the response includes Completeness: The implementation addresses the primary redirect-rewrite scenario but leaves important behavioral gaps untested and unresolved. There is only one new test for the basic same-host upgrade path ( Risks: Main risk is compatibility/regression in redirect handling: same-host HTTP redirects on non-default ports may now be rewritten to HTTPS unexpectedly because the HSTS cache key ignores port ( Missing tests: Missing tests include: (1) a redirect from Follow-up work: If the feature is kept, follow up by documenting the redirect/HSTS behavior change in user-facing release notes and by clarifying the intended scope of the cache key (hostname-only vs origin/port-aware). A second follow-up would be to add a focused test matrix around Decision — REQUEST_CHANGES: Requesting changes because there is a concrete compatibility/correctness concern in the shipped behavior: the new HSTS cache is keyed only by hostname, but redirect rewriting preserves arbitrary ports, so the session can now rewrite redirects for the same host on different ports without evidence that those ports should be treated as HSTS-covered. The root feature is partly implemented, but significant edge-case coverage is missing, so the change does not yet meet the criteria for safe approval. 📁 Files changedImportant Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant Session
participant RedirectMixin as SessionRedirectMixin
participant Response
Caller->>Session: resolve_redirects(resp, req, yield_requests=True)
Session->>RedirectMixin: _update_hsts_hosts(resp)
RedirectMixin->>Response: read resp.url + Strict-Transport-Security
RedirectMixin-->>Session: store hostname in session HSTS set
Session->>RedirectMixin: get_redirect_target(resp)
loop while redirect exists
Session->>RedirectMixin: _upgrade_hsts_redirect(resp, url)
alt same hostname, original resp https, redirect url http, host in HSTS set
RedirectMixin-->>Session: return https-upgraded URL
else conditions not met
RedirectMixin-->>Session: return original URL
end
Session-->>Caller: yield prepared redirect request/response
Note over Session,RedirectMixin: New responses update the session HSTS cache before the next redirect step
end
Actionable comments posted: 2 (0 suggested change(s), 2 fix-session candidate(s)) Fix all findings: comment 📋 Reviewed against: lint (python): Aziron Pulse — sandbox + MCP-assisted LLM review with native code intelligence. |
|
🪄 Autofix — generate a fix for all Aziron Pulse findings on this PR:
Tick the box above (or comment |
Incident Summary
Requests followed a redirect from
https://olb.bsf.nettohttp://olb.bsf.net/login/despite the reporter stating the site advertisedStrict-Transport-Security. Because the site did not listen on port 80, Requests attempted the downgraded HTTP request and timed out with anurllib3.exceptions.MaxRetryError.Root Cause Mapping
The RCA identified the likely root cause as redirect handling preserving absolute
http://Locationtargets without an HSTS cache or upgrade step. The exact original redirect decision line was not verified in the shared flow-memory. The implemented fix was reported insrc/requests/sessions.py, but exact changed line numbers were not available in the shared context.Files Reviewed
src/requests/sessions.py— changed to record HTTPS hosts that returnStrict-Transport-Securityand upgrade subsequent same-hosthttp://redirect targets tohttps://.tests/test_requests.py— changed to addTestRequests::test_hsts_redirect_upgrades_http_location.Fix Verification
QA did not pass. QA judged that the implementation targets the reported HSTS redirect behavior, but deterministic validation was blocked because the runtime lacked a usable Python/pytest setup.
Test Evidence
Automated verification did not complete successfully.
Commands/results:
pytest tests/test_requests.py::TestRequests::test_hsts_redirect_upgrades_http_location tests/test_requests.py::TestRequests::test_auth_is_stripped_on_http_downgrade tests/test_requests.py::test_requests_are_updated_each_time -q— failed:bash: pytest: command not found.python -m pytest tests/test_requests.py::TestRequests::test_hsts_redirect_upgrades_http_location tests/test_requests.py::TestRequests::test_auth_is_stripped_on_http_downgrade tests/test_requests.py::test_requests_are_updated_each_time -q— exit code 127:/bin/sh: 1: python: not found.python3 -m pytest tests/test_requests.py::TestRequests::test_hsts_redirect_upgrades_http_location tests/test_requests.py::TestRequests::test_auth_is_stripped_on_http_downgrade tests/test_requests.py::test_requests_are_updated_each_time -q— exit code 1:/usr/bin/python3: No module named pytest.Atlas status check reported the server available, local tier, with repository
dominic097/requestsindexed with 1144 symbols.Regression Analysis
Reviewer findings:
pytestwas unavailable.Risk remains that the HSTS redirect behavior or nearby redirect/auth behavior could regress until tests run successfully.
Deployment Considerations
No migrations or configuration changes were reported. Rollout should wait for a passing targeted test run in an environment with Python and pytest installed.
Future Prevention Recommendations
http://redirect upgrades.src/requests/sessions.py.Approval Decision
REQUEST_CHANGES — reviewer requested changes because QA failed, automated tests were not executed successfully, and the final implementation could not be independently confirmed from the truncated shared context.
Fixes #17
Opened autonomously by Aziron Pulse (FusionX agent).