Skip to content

Implement Webhook URL Validation to Prevent SSRF#33

Open
Snider wants to merge 4 commits intodevfrom
fix/webhook-ssrf-vulnerability-18092576128623276148
Open

Implement Webhook URL Validation to Prevent SSRF#33
Snider wants to merge 4 commits intodevfrom
fix/webhook-ssrf-vulnerability-18092576128623276148

Conversation

@Snider
Copy link
Contributor

@Snider Snider commented Feb 4, 2026

This change implements Server-Side Request Forgery (SSRF) protection for the webhook system.

Key changes:

  1. New WebhookUrlValidator Service: A dedicated service that validates URLs by resolving their hostnames to IPs (supporting both IPv4 and IPv6) and checking them against restricted ranges using filter_var with FILTER_FLAG_NO_PRIV_RANGE and FILTER_FLAG_NO_RES_RANGE. It also includes manual blocks for loopback addresses, common localhost names, and cloud metadata endpoints (e.g., 169.254.169.254).
  2. Model Validation: Updated the WebhookEndpoint model to validate URLs in the createForWorkspace method and added a setUrlAttribute mutator to ensure all updates to the URL are validated.
  3. Runtime Protection: Added a final check in DeliverWebhookJob just before the HTTP request is made. If the URL is found to be restricted at runtime, the delivery is cancelled, marked as failed with a security log entry, and retries are disabled.
  4. Tests: Added a new feature test suite WebhookUrlValidationTest that covers blocked hostnames, private IPs, link-local addresses, and valid public URLs.

This provides multiple layers of defense against attackers trying to use webhooks to scan internal networks or access sensitive cloud metadata.

Fixes #4


PR created automatically by Jules for task 18092576128623276148 started by @Snider

- Created WebhookUrlValidator service to block private, reserved, and loopback IPs
- Applied validation to WebhookEndpoint creation and updates
- Added runtime URL validation in DeliverWebhookJob before delivery
- Added comprehensive feature tests for various SSRF scenarios
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Snider, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security of the webhook system by implementing multi-layered Server-Side Request Forgery (SSRF) protection. It introduces a dedicated validation service and integrates its checks at multiple points: during webhook endpoint creation, updates, and critically, just before any external HTTP request is made. This ensures that webhooks cannot be maliciously used to scan internal networks or access sensitive cloud metadata, thereby bolstering the application's overall security posture.

Highlights

  • New WebhookUrlValidator Service: A dedicated service has been introduced to validate webhook URLs. It resolves hostnames to IPs (supporting both IPv4 and IPv6) and checks them against restricted ranges, including private, reserved, loopback addresses, common localhost names, and cloud metadata endpoints (e.g., 169.254.169.254).
  • Model Validation: The WebhookEndpoint model now includes validation for URLs. This ensures that any URL provided during endpoint creation (createForWorkspace) or updated via the setUrlAttribute mutator is validated against the defined security policies.
  • Runtime Protection: A final security check is performed in the DeliverWebhookJob just before an HTTP request is made. If a restricted URL is detected at this stage, the delivery is cancelled, marked as failed with a security log entry, and all further retries are disabled.
  • Comprehensive Testing: A new feature test suite, WebhookUrlValidationTest, has been added. It covers various scenarios, including blocked hostnames, private IPs, link-local addresses, and ensures that valid public URLs are allowed, providing robust coverage for the new validation logic.
Changelog
  • src/Api/Boot.php
    • Registered the new WebhookUrlValidator service as a singleton in the application container.
  • src/Api/Jobs/DeliverWebhookJob.php
    • Imported the WebhookUrlValidator service.
    • Added a runtime validation check for the webhook URL before initiating the HTTP request. If the URL is restricted, the delivery is cancelled, marked as failed, and retries are prevented.
  • src/Api/Models/WebhookEndpoint.php
    • Imported the WebhookUrlValidator service.
    • Integrated URL validation into the createForWorkspace static method, throwing an InvalidArgumentException for restricted URLs.
    • Implemented a setUrlAttribute mutator to validate the URL whenever it is updated, ensuring ongoing security compliance.
  • src/Api/Services/WebhookUrlValidator.php
    • Added a new service class WebhookUrlValidator responsible for validating webhook URLs.
    • The validator checks for valid HTTP/HTTPS schemes, blocks common localhost names, resolves hostnames to IPs (IPv4 and IPv6), and verifies that resolved IPs are not private, reserved, loopback, or cloud metadata addresses.
    • Includes filter_var with FILTER_FLAG_NO_PRIV_RANGE and FILTER_FLAG_NO_RES_RANGE for initial IP filtering, complemented by manual checks for specific ranges like 169.254.x.x and IPv6 link-local addresses.
  • src/Api/Tests/Feature/WebhookUrlValidationTest.php
    • Added a new feature test suite to verify the functionality of WebhookUrlValidator.
    • Includes tests for blocking various restricted URLs (localhost, private IPv4, link-local, loopback IPv6, non-HTTP schemes) and allowing valid public URLs.
    • Tests that exceptions are thrown when creating or updating WebhookEndpoint with restricted URLs.
    • Verifies that DeliverWebhookJob correctly cancels delivery and marks it as failed if a URL becomes restricted at runtime.
Activity
  • Pull request was automatically created by Jules for task [18092576128623276148] initiated by @Snider.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Feb 4, 2026

QA Pipeline Results

Check Status Details
Tests tests, assertions
PHPStan errors
Psalm issues
Code Style files need formatting
Security vulnerabilities
Artifacts
  • test-results.xml - JUnit test results
  • phpstan.json - PHPStan analysis
  • psalm.json / psalm.sarif - Psalm analysis
  • pint.json - Code style report
  • audit.json - Security audit

Generated by core php qa pipeline

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces robust SSRF protection for webhooks, which is an excellent security enhancement. The implementation is well-structured with multiple layers of validation: at creation/update time in the WebhookEndpoint model, and as a final check at runtime in the DeliverWebhookJob. The new WebhookUrlValidator service is comprehensive, and the added tests cover a wide range of scenarios.

I've made a couple of suggestions in the WebhookUrlValidator service to simplify the code by removing redundant checks and to improve the robustness of DNS resolution. Overall, this is a solid implementation.

Comment on lines +85 to +112
protected function resolveHost(string $host): array
{
$ips = [];

// IPv4 resolution
$ipv4s = gethostbynamel($host);
if ($ipv4s !== false) {
$ips = array_merge($ips, $ipv4s);
}

// IPv6 resolution (if dns_get_record is available)
if (function_exists('dns_get_record')) {
try {
$ipv6s = @dns_get_record($host, DNS_AAAA);
if ($ipv6s) {
foreach ($ipv6s as $record) {
if (isset($record['ipv6'])) {
$ips[] = $record['ipv6'];
}
}
}
} catch (\Throwable $e) {
// Ignore DNS errors, rely on IPv4 or IP-based check
}
}

return array_unique($ips);
}

Choose a reason for hiding this comment

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

medium

The resolveHost method uses gethostbynamel for IPv4 resolution, which is an older function with some known issues (e.g., it's blocking, and its behavior can be inconsistent in some environments). For improved robustness and consistency, consider refactoring this method to use dns_get_record for both IPv4 (A records) and IPv6 (AAAA records) lookups. This would unify the DNS resolution logic and leverage a more modern PHP function.

Comment on lines +130 to +152
if ($isPublic === false) {
return true;
}

// Additional manual checks for safety
$lowIp = strtolower($ip);

// IPv6 loopback
if ($lowIp === '::1' || $lowIp === '0000:0000:0000:0000:0000:0000:0000:0001') {
return true;
}

// Check for 169.254.x.x (Link-local / AWS Metadata) - double check
if (str_starts_with($ip, '169.254.')) {
return true;
}

// Check for IPv6 link-local (fe80::/10)
if (str_starts_with($lowIp, 'fe80:')) {
return true;
}

return false;

Choose a reason for hiding this comment

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

medium

The manual checks for private and reserved IP addresses are redundant. The filter_var call on line 124 with the flags FILTER_FLAG_NO_PRIV_RANGE and FILTER_FLAG_NO_RES_RANGE already covers all these cases, including IPv4/IPv6 loopback, link-local, and private ranges. The logic can be simplified to just check the result of filter_var.

        return $isPublic === false;
    }

- Created WebhookUrlValidator to block restricted IP ranges (localhost, private, cloud metadata)
- Applied URL validation to WebhookEndpoint creation, updates, and delivery
- Fixed CI failure by adding missing host-uk/core repository to composer.json
- Set minimum-stability to dev to allow resolution of internal dependencies
- Fixed invalid checkout version in ci.yml workflow
- Created WebhookUrlValidator to block private/reserved IP ranges
- Applied multi-layered URL validation to WebhookEndpoint and DeliverWebhookJob
- Fixed CI failure by correctly configuring host-uk/core dependency
- Added missing host-uk/core-php VCS repository with no-api: true to composer.json
- Fixed non-existent actions/checkout version in ci.yml
- Created WebhookUrlValidator to block restricted IP ranges
- Applied multi-layered URL validation to WebhookEndpoint and DeliverWebhookJob
- Fixed CI failures by adding missing dev dependencies to composer.json
- Configured host-uk/core repository with no-api: true to resolve VCS dependency
- Downgraded actions/checkout to v4 in ci.yml workflow
@Snider Snider marked this pull request as ready for review February 5, 2026 03:25
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

Warning

Rate limit exceeded

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

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/webhook-ssrf-vulnerability-18092576128623276148

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

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.

Security: Webhook URL SSRF vulnerability - no validation of internal/private network URLs

1 participant