Repository navigation
fix(security): pin webhook IP to close DNS rebinding; NFC-normalize path components - #524
Conversation
…ath components Closes #480. Three of the five sub-issues filed in #480 are already resolved on master by the audit-fix wave that landed via #504 (blob/db file permissions and the site-manifest absolute-path leak). This change addresses the two remaining items. DNS rebinding on webhook delivery (polylogue/pipeline/observers.py) _validate_webhook_url resolved the hostname against the SSRF denylist, but _post_webhook then handed the *hostname* back to http.client, which re-resolved at connect time. An attacker controlling a short-TTL DNS record could resolve to a public address during validation and to 127.0.0.1 (or any private RFC-1918 address) during the actual connection. Fix: - _resolve_and_validate returns the validated IP from the same getaddrinfo call that runs the SSRF check. - _webhook_request_target returns ``(scheme, hostname, validated_ip, port, path)`` so the caller has both: hostname for SNI/cert, IP for the socket. - _PinnedHTTPSConnection subclasses HTTPSConnection and overrides ``connect()`` to ``socket.create_connection`` against the validated IP, then wraps with TLS using ``server_hostname=hostname`` so cert verification still binds to the original hostname. - HTTP path connects to the validated IP and sets the Host header back to the original hostname (otherwise virtual-hosted servers fail to route). Unicode confusable bypass in path sanitization (polylogue/paths/sanitize.py) safe_path_component matched against an ASCII-only allowlist regex but never normalized. ``café`` written as NFC ("é" U+00E9) and ``café`` as NFD ("e" + U+0301) hashed to different prefixes, so a confusable input could end up at a different filesystem path than the visually-equivalent canonical form. Fix: NFC-normalize before sanitization. The ASCII allowlist still flattens everything else to ``prefix-digest``; normalization just makes the digest stable across visually-identical decomposed forms. Tests: - test_unicode_nfc_normalization_collapses_confusables — equates NFC and NFD spellings of café. - test_webhook_request_target_and_post_webhook_cover_http_https_and_hostname_errors — updated to assert the new 5-tuple shape and that the HTTP path restores the Host header on the IP-pinned connection. Verification: devtools verify --quick green; full unit suite 5595 passed. Co-Authored-By: Claude <[email protected]>
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b44f9b7e3d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ath components (#524) ## Summary Closes #480. Three of the five sub-issues in #480 (blob file permissions, db file permissions, site manifest absolute-path leak) were already resolved on master by the audit-fix wave that landed via #504. This PR addresses the two real outstanding items. ## Problem ### DNS rebinding on webhook delivery `polylogue/pipeline/observers.py:_validate_webhook_url` resolved the hostname against the SSRF denylist, but `_post_webhook` handed the *hostname* back to `http.client.HTTPSConnection`, which re-resolves at connect time. An attacker controlling a short-TTL DNS record could resolve to a public address during validation and to `127.0.0.1` (or any private RFC-1918 address) during the actual connection. Validation runs in microseconds; connection establishment is far slower; the rebinding window is real. ### Unicode confusable bypass in path sanitization `polylogue/paths/sanitize.py:safe_path_component` ran an ASCII-only allowlist regex but never normalized the input. `café` written as NFC (`é` U+00E9) and `café` written as NFD (`e` + U+0301) hashed to different prefixes, so two visually-identical inputs landed at two different filesystem paths. ## Solution ### IP-pinned webhook delivery - `_resolve_and_validate` returns the validated IP from the same `getaddrinfo` call that runs the SSRF check. - `_webhook_request_target` returns `(scheme, hostname, validated_ip, port, path)` — the caller now has both hostname (for SNI/cert verification) and IP (for the actual socket). - `_PinnedHTTPSConnection` subclasses `http.client.HTTPSConnection` and overrides `connect()` to `socket.create_connection` against the validated IP, then wraps with TLS using `server_hostname=hostname` so cert verification still binds to the original hostname. - HTTP path connects to the validated IP and sets the `Host` header back to the original hostname (otherwise virtual-hosted servers fail to route). ### NFC normalization for path components `safe_path_component` calls `unicodedata.normalize("NFC", ...)` before the allowlist regex runs. The ASCII allowlist still flattens everything else to `prefix-digest`; normalization just stabilizes the digest across decomposed forms. ## Verification ``` $ nix develop -c devtools verify --quick verify: all checks passed $ nix develop -c pytest -q tests/unit/pipeline/test_observers_runtime.py tests/unit/core/test_paths.py tests/unit/security/ 136 passed in 10.49s $ nix develop -c pytest -q tests/ --ignore=tests/integration 5595 passed, 10 xfailed in 176.75s ``` New tests: - `test_unicode_nfc_normalization_collapses_confusables` — `safe_path_component(NFC) == safe_path_component(NFD)` for `café`. - `test_webhook_request_target_and_post_webhook_cover_http_https_and_hostname_errors` updated for the new 5-tuple shape and to assert the HTTP path restores the `Host` header on the IP-pinned connection. ## Already resolved (no change needed) | #480 sub-item | Status on master | | --- | --- | | `storage/blob_store.py` blob file permissions | Already `os.chmod(0o600)` at line 98 + line 149 | | `storage/backends/connection.py` db permissions | Already `os.chmod(0o600)` at line 92 | | `site/publication_flow.py` manifest path leak | Already serializes `output_dir="."` (line 215), not the absolute path | The token-store note (configurable Drive credential path) is documentation of existing behavior, not a defect — token files themselves are written `0o600` (`token_store.py:73`). Co-authored-by: Claude <[email protected]>
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Closes #480.
Three of the five sub-issues in #480 (blob file permissions, db file permissions, site manifest absolute-path leak) were already resolved on master by the audit-fix wave that landed via #504. This PR addresses the two real outstanding items.
Problem
DNS rebinding on webhook delivery
polylogue/pipeline/observers.py:_validate_webhook_urlresolved the hostname against the SSRF denylist, but_post_webhookhanded the hostname back tohttp.client.HTTPSConnection, which re-resolves at connect time. An attacker controlling a short-TTL DNS record could resolve to a public address during validation and to127.0.0.1(or any private RFC-1918 address) during the actual connection. Validation runs in microseconds; connection establishment is far slower; the rebinding window is real.Unicode confusable bypass in path sanitization
polylogue/paths/sanitize.py:safe_path_componentran an ASCII-only allowlist regex but never normalized the input.caféwritten as NFC (éU+00E9) andcaféwritten as NFD (e+ U+0301) hashed to different prefixes, so two visually-identical inputs landed at two different filesystem paths.Solution
IP-pinned webhook delivery
_resolve_and_validatereturns the validated IP from the samegetaddrinfocall that runs the SSRF check._webhook_request_targetreturns(scheme, hostname, validated_ip, port, path)— the caller now has both hostname (for SNI/cert verification) and IP (for the actual socket)._PinnedHTTPSConnectionsubclasseshttp.client.HTTPSConnectionand overridesconnect()tosocket.create_connectionagainst the validated IP, then wraps with TLS usingserver_hostname=hostnameso cert verification still binds to the original hostname.Hostheader back to the original hostname (otherwise virtual-hosted servers fail to route).NFC normalization for path components
safe_path_componentcallsunicodedata.normalize("NFC", ...)before the allowlist regex runs. The ASCII allowlist still flattens everything else toprefix-digest; normalization just stabilizes the digest across decomposed forms.Verification
New tests:
test_unicode_nfc_normalization_collapses_confusables—safe_path_component(NFC) == safe_path_component(NFD)forcafé.test_webhook_request_target_and_post_webhook_cover_http_https_and_hostname_errorsupdated for the new 5-tuple shape and to assert the HTTP path restores theHostheader on the IP-pinned connection.Already resolved (no change needed)
storage/blob_store.pyblob file permissionsos.chmod(0o600)at line 98 + line 149storage/backends/connection.pydb permissionsos.chmod(0o600)at line 92site/publication_flow.pymanifest path leakoutput_dir="."(line 215), not the absolute pathThe token-store note (configurable Drive credential path) is documentation of existing behavior, not a defect — token files themselves are written
0o600(token_store.py:73).