fix: disallow SSRF via remote $ref#2224
Merged
daniel-kmiecik merged 3 commits intomasterfrom Sep 1, 2025
Merged
Conversation
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
Dismissed
Show dismissed
Hide dismissed
ewaostrowska
requested changes
Aug 29, 2025
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
Outdated
Show resolved
Hide resolved
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
Show resolved
Hide resolved
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
Show resolved
Hide resolved
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
Show resolved
Hide resolved
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceVisitor.java
Outdated
Show resolved
Hide resolved
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
Show resolved
Hide resolved
ewaostrowska
approved these changes
Sep 1, 2025
Contributor
|
Looks good :) |
There was a problem hiding this comment.
Pull Request Overview
This PR implements security measures to prevent Server-Side Request Forgery (SSRF) attacks via remote $ref in the Swagger parser by introducing URL validation and restricting access to potentially dangerous network locations.
Key changes:
- Adds
PermittedUrlsCheckerfunctionality to validate URLs before making remote requests - Implements redirect limits and protocol validation to prevent abuse
- Updates test infrastructure to support HTTPS and handle URL security checks
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Removes commented dependencies and adds system property for testing |
| RemoteUrl.java | Refactors URL handling with redirect limits, security checks, and improved error handling |
| RefUtils.java | Updates method signatures to include PermittedUrlsChecker parameter |
| Multiple test files | Updates tests to use HTTPS, adds security validation, and improves test structure |
| PermittedUrlsCheckerAllowLocal.java | New test utility class to allow local connections during testing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RemoteUrl.java
Show resolved
Hide resolved
modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/reference/ReferenceVisitor.java
Show resolved
Hide resolved
modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/RemoteUrlTest.java
Outdated
Show resolved
Hide resolved
modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/RemoteUrlTest.java
Outdated
Show resolved
Hide resolved
djankows
approved these changes
Sep 1, 2025
|
Fixes #2206 |
Contributor
Author
|
@rootxjs, thank you for bringing this to our attention! I am closing the issue :) |
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.
The current implementation of the URL validation logic bypasses the security controls of setSafelyResolveURL when an HTTP redirect is encountered. This allows a malicious OpenAPI specification to force the validator's host to connect to internal network resources, creating a significant security risk. This is a fix for this securrity issue.