Skip to content

fix(security): pin webhook IP to close DNS rebinding; NFC-normalize path components - #524

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/security-sweep-permissions-leaks
Apr 27, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/security-sweep-permissions-leaks

Conversation

@Sinity

@Sinity Sinity commented Apr 27, 2026

Copy link
Copy Markdown
Owner

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).

…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]>
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 48 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 167ad044-82b4-40a0-ae87-cce15f695355

📥 Commits

Reviewing files that changed from the base of the PR and between 574ad60 and b44f9b7.

📒 Files selected for processing (4)
  • polylogue/paths/sanitize.py
  • polylogue/pipeline/observers.py
  • tests/unit/core/test_paths.py
  • tests/unit/pipeline/test_observers_runtime.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/security-sweep-permissions-leaks

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread polylogue/pipeline/observers.py Resolved
@Sinity
Sinity merged commit faf9e53 into master Apr 27, 2026
13 checks passed
@Sinity
Sinity deleted the feature/fix/security-sweep-permissions-leaks branch April 27, 2026 04:08
@Sinity
Sinity requested a review from Copilot May 1, 2026 00:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sinity added a commit that referenced this pull request May 7, 2026
…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]>
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(security): file permissions, manifest path leaks, config dedup

2 participants