Skip to content
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

Support com/google/common/escape/Escaper as sanitizer #504

Closed
h3xstream opened this issue Sep 20, 2019 · 4 comments
Closed

Support com/google/common/escape/Escaper as sanitizer #504

h3xstream opened this issue Sep 20, 2019 · 4 comments
Assignees
Labels
enhancement New feature or improvement to existing detector. good first issue hacktoberfest

Comments

@h3xstream
Copy link
Member

Description

com/google/common/escape/Escaper.escape() is often used to encode URL parameter.

While the interface is generic and could be implemented by any type of escaping, it is highly likely to be for URL. https://guava.dev/releases/19.0/api/docs/com/google/common/net/UrlEscapers.html

Code

Test case provided by @ RichardBradley

Bad :

import javax.ws.rs.core.Response;
import org.apache.http.client.methods.HttpGet;

public Response get(String x, String y) throws IOException {

    String url = String.format("%s/%s",
            x,
            y);

    HttpGet request = new HttpGet(url); // HERE

    ...
}

Good:

import javax.ws.rs.core.Response;
import org.apache.http.client.methods.HttpGet;
import static com.google.common.net.UrlEscapers.urlPathSegmentEscaper;

public Response get(String x, String y) throws IOException {

    String url = String.format("%s/%s",
            urlPathSegmentEscaper().escape(x),
            urlPathSegmentEscaper().escape(y));

    HttpGet request = new HttpGet(url);

    ...
}
@h3xstream h3xstream added enhancement New feature or improvement to existing detector. good first issue hacktoberfest labels Sep 20, 2019
@h3xstream
Copy link
Member Author

Open to close #346

@h3xstream
Copy link
Member Author

h3xstream commented Sep 20, 2019

For somebody to do this "quick" win:
Here is an example of configuration for URLEncoder.

java/net/URLEncoder.encode(Ljava/lang/String;)Ljava/lang/String;:0|+URL_ENCODED,+XSS_SAFE
java/net/URLEncoder.encode(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;:1|+URL_ENCODED,+XSS_SAFE
java/net/URLDecoder.decode(Ljava/lang/String;)Ljava/lang/String;:0|-URL_ENCODED,-XSS_SAFE
java/net/URLDecoder.decode(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;:1|-URL_ENCODED,-XSS_SAFE

@thiyagu-7
Copy link
Contributor

I would like to take this for this hacktoberfest

@h3xstream
Copy link
Member Author

@thiyagu-7 Perfect! I have assigned you to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing detector. good first issue hacktoberfest
Projects
None yet
Development

No branches or pull requests

2 participants