fix: guard legacy redirect routes against open-redirect (B8 / J11) - #70
Merged
Merged
Conversation
The legacy /webhooks/* and /cron/* compatibility routes interpolate a user-controlled value (name/target_job/target_webhook) straight into a 301 redirect path. A value like //evil.com or /\evil.com makes the result protocol-relative, so the browser resolves it off-site (open redirect / phishing; CodeQL py/url-redirection). Add bin/url_safety.safe_path_segment (no third-party imports, no cycle risk) that strips slashes/backslashes from single-segment names, and apply it to all five app.py interpolated redirects. The template_view /workflows/<path:rest> catch-all guards against backslash/'//'/scheme tails, falling back to the catalog. Tests cover off-site payloads per route plus the normal-value happy paths.
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.
Closes bug B8 (CodeQL
py/url-redirection/ open redirect), part of the J11 CodeQL work.The issue
The legacy
/webhooks/*and/cron/*compatibility routes build a 301 redirect by interpolating a user-controlled value (name/target_job/target_webhook) straight into the path:redirect(f"/automations/jamfpro/{name}/edit"). A value like//evil.comor/\evil.commakes the result protocol-relative, so the browser resolves it off-site — an open redirect / phishing vector.The fix
bin/url_safety.py→safe_path_segment(value): strips/and\from a single path-segment value (no third-party imports, no cycle risk).app.pyinterpolated redirects sanitize their segment; an empty/all-separator value redirects to the automation list page rather than building a dangling//path.views/template_view.py's/workflows/<path:rest>catch-all guards against backslash //// scheme tails, falling back to the catalog.tests/test_redirect_safety.py: off-site payloads (//evil.com,/\evil.com,\\evil.com,https://evil.com,////,/) per route assert theLocationis always a local/automations(or/templates) path — never protocol-relative or off-site — plus normal-value happy-path tests. (Verified the tests have teeth: reverting a site to raw fails them.)J11 scope note
This is the concrete code fix. The remaining J11 work — dispositioning the CodeQL alert queue (the critical SSRF is accepted-by-design; ~19 alerts live in files develop already deleted and auto-resolve at release; give develop a scan baseline) — is deferred to the
develop → mainrelease PR, when the true post-merge alert set is visible.Targets
developfor the batched v3.2 release. Full suite green (145 passed), ruff clean.