-
Notifications
You must be signed in to change notification settings - Fork 0
Sandboxed URL creation to prevent SSRF attacks #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
* THE SOFTWARE. | ||
*/ | ||
|
||
import io.github.pixee.security.HostValidator; | ||
import io.github.pixee.security.Urls; | ||
import java.net.*; | ||
import java.io.*; | ||
import java.nio.channels.*; | ||
|
@@ -113,7 +115,7 @@ protected PasswordAuthentication getPasswordAuthentication() { | |
} | ||
}); | ||
} | ||
URL website = new URL(urlString); | ||
URL website = Urls.create(urlString, Urls.HTTP_PROTOCOLS, HostValidator.DENY_COMMON_INFRASTRUCTURE_TARGETS); | ||
ReadableByteChannel rbc; | ||
rbc = Channels.newChannel(website.openStream()); | ||
FileOutputStream fos = new FileOutputStream(destination); | ||
Comment on lines
115
to
121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Recommended Solution: |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
*/ | ||
package com.iluwatar.promise; | ||
|
||
import io.github.pixee.security.HostValidator; | ||
import io.github.pixee.security.Urls; | ||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
Comment on lines
24
to
31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import statements for |
||
|
@@ -98,7 +100,7 @@ public static Integer countLines(String fileLocation) { | |
*/ | ||
public static String downloadFile(String urlString) throws IOException { | ||
LOGGER.info("Downloading contents from url: {}", urlString); | ||
var url = new URL(urlString); | ||
var url = Urls.create(urlString, Urls.HTTP_PROTOCOLS, HostValidator.DENY_COMMON_INFRASTRUCTURE_TARGETS); | ||
var file = File.createTempFile("promise_pattern", null); | ||
try (var bufferedReader = new BufferedReader(new InputStreamReader(url.openStream())); | ||
var writer = new FileWriter(file)) { | ||
Comment on lines
100
to
106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Recommended Solution: |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imports for
HostValidator
andUrls
fromio.github.pixee.security
are included, but there is no indication that these classes are being used in the code. This could lead to confusion and maintainability issues.Recommended Solution:
Remove the unused imports if they are not necessary. If they are intended for future use, consider adding a comment to clarify their purpose.