security: fix SSRF redirect bypass, timing-safe OAuth, atomic credentials#200
Open
eesb99 wants to merge 5 commits intoCraftOS-dev:V1.2.3from
Open
security: fix SSRF redirect bypass, timing-safe OAuth, atomic credentials#200eesb99 wants to merge 5 commits intoCraftOS-dev:V1.2.3from
eesb99 wants to merge 5 commits intoCraftOS-dev:V1.2.3from
Conversation
…ial perms - Fix socket.gaierror -> _socket.gaierror reference bug that silently disabled SSRF protection when DNS resolution failed - Use hmac.compare_digest() for OAuth state comparison to prevent timing side-channel attacks - Use os.open() with 0o600 mode for atomic credential file permissions instead of write-then-chmod race Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rcement SSRF (http_request.py): - Extract _is_url_ssrf_safe() helper for reuse across redirect hops - Disable allow_redirects in requests lib, manually follow redirects with SSRF validation on each hop (closes redirect bypass) - Remove fail-open except Exception: pass -- DNS failures now block the request instead of silently allowing it - Unresolvable hostnames return an error (fail closed) OAuth CSRF (oauth_server.py): - Explicit 3-way state handling: no state expected (warn + allow), state expected but missing from callback (reject), mismatch (reject) - Previously silently skipped validation when state was absent Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4 tasks
…l perms Review-driven fixes: - SSRF: add scheme whitelist (http/https only), strip auth headers on cross-origin redirects, strip body on GET downgrade, preserve method for 307/308 per RFC 7231 - OAuth: use `is None` checks to prevent empty-string state bypass, move `import hmac` to module top-level - Credentials: add os.fchmod() to enforce 0o600 on pre-existing files - Python compat: quote `str | None` annotation for 3.9 support, promote _BLOCKED_HOSTS to frozenset Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace 6 repeated error-response dicts with _error() helper - Move urljoin import out of redirect loop, combine with urlparse Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
File was tracked despite .gitignore rule. Removed from index so credentials are no longer committed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Incremental security hardening on top of PR #195 (already merged to V1.2.3). These fixes address 3 remaining vulnerabilities:
http_request.py): Disable automatic redirects and manually follow each hop with SSRF validation, preventing attackers from redirecting to internal IPs. Also fix_socket.gaierrorreference bug and switch to fail-closed on DNS errors.oauth_server.py): Usehmac.compare_digest()for constant-time state comparison. Add explicit 3-way state handling: no state expected (warn + allow), state expected but missing from callback (reject), mismatch (reject).credentials.py): Replace write-then-chmod with atomicos.open()using0o600mode to eliminate the TOCTOU race window.Files changed (3)
app/data/action/http_request.py_is_url_ssrf_safe()helperagent_core/core/credentials/oauth_server.pyapp/external_comms/credentials.pyos.open()Test plan
http://attacker.com->http://169.254.169.254)🤖 Generated with Claude Code