Skip to content

Guard UnifiedPush endpoints against SSRF#25

Open
juanfradb wants to merge 1 commit into
MostroP2P:mainfrom
juanfradb:fix/unifiedpush-ssrf-guard
Open

Guard UnifiedPush endpoints against SSRF#25
juanfradb wants to merge 1 commit into
MostroP2P:mainfrom
juanfradb:fix/unifiedpush-ssrf-guard

Conversation

@juanfradb
Copy link
Copy Markdown
Contributor

Summary

  • validate URL-shaped Android/UnifiedPush tokens as public HTTPS endpoints before storing them
  • revalidate UnifiedPush endpoints before dispatch and add a DNS resolver that filters connection-time private/internal DNS results
  • add optional UNIFIEDPUSH_ALLOWED_HOSTS_REGEX host allowlist and document the policy

Fixes #4.
Also covers the registration-side validation requested in #13.

Validation

  • cargo fmt
  • cargo test unifiedpush -- --nocapture
  • cargo test rejects_invalid_unifiedpush_allowed_hosts_regex -- --nocapture
  • cargo test register_rejects -- --nocapture
  • cargo test register_accepts_public_https_unifiedpush_url -- --nocapture
  • cargo test
  • cargo clippy --all-targets -- -D warnings
  • git diff --check

Note: cargo test --doc reports no library targets for this binary crate.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Warning

Rate limit exceeded

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

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4de28252-d708-4339-bd67-b5c38ac7c035

📥 Commits

Reviewing files that changed from the base of the PR and between 893e7e1 and 9b9a757.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • .env.example
  • Cargo.toml
  • config.toml.example
  • docs/api.md
  • docs/configuration.md
  • docs/unifiedpush.md
  • src/api/routes.rs
  • src/api/test_support.rs
  • src/config.rs
  • src/main.rs
  • src/push/mod.rs
  • src/push/unifiedpush.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

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

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: 9b9a7574a8

ℹ️ 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 src/push/unifiedpush.rs
);

let response = self.client.post(device_token).json(&payload).send().await?;
let response = self.client.post(endpoint_url).json(&payload).send().await?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Revalidate or disable UnifiedPush redirects

When a registered public HTTPS endpoint returns a redirect, this request uses reqwest's default redirect policy, which follows redirects automatically, but only the original endpoint_url was validated. In that scenario a valid distributor can redirect the server to an unvalidated scheme or host (for example outside UNIFIEDPUSH_ALLOWED_HOSTS_REGEX, or a private IP literal that does not require DNS resolution), bypassing the SSRF/TLS policy this change is adding. Disable redirects for UnifiedPush or install a redirect policy that validates every Location before following it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

@AndreaDiazCorreia AndreaDiazCorreia left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this. A few things need to change before merge:

Blocking

  1. Redirects bypass the SSRF guard. The shared reqwest::Client uses the default redirect policy, so a distributor can respond 302 Location: https://10.0.0.1/... (literal IP skips PublicDnsResolver) or redirect to a public host outside
  2. UNIFIEDPUSH_ALLOWED_HOSTS_REGEX. Same concern Codex raised. Please disable redirects on the UnifiedPush dispatch path or install a policy that re-runs validate_endpoint_url on every Location. Note http_client is shared with FCM — a separate client for UnifiedPush is probably cleaner.
  3. New direct deps. regex and hyper are added to Cargo.toml. Per CLAUDE.md constraint 6, that needs explicit maintainer sign-off. hyper is unavoidable for reqwest::dns::Resolve; regex could be swapped for suffix matching if we want to avoid it.
  4. /api/register fixture regression. URL-shaped Android tokens that previously got 200 OK now return 400 Invalid UnifiedPush endpoint URL, breaking the byte-identity invariant in CLAUDE.md constraint 3. Either document a new exception in CLAUDE.md (like the whitelist 403) or move the rejection to dispatch-only.

The IPv4 classifier, double-validation pattern, fail-fast on bad regex, and test coverage on the acceptance criteria all look great. Once these three are addressed I think this is good to merge.

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.

[P0] [security] Validar URL del endpoint UnifiedPush para evitar SSRF

2 participants