-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Java: Add models for the Spring web.util
package
#5953
Conversation
ae2f6ea
to
0264aff
Compare
0264aff
to
1d6726a
Compare
55ffef8
to
6b53162
Compare
34a36c4
to
3d9808b
Compare
|
"java.util;HashMap;false;HashMap;;;MapKey of Argument[0];MapKey of Argument[-1];value", | ||
"java.util;HashMap;false;HashMap;;;MapValue of Argument[0];MapValue of Argument[-1];value", |
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.
I think this ought to be restricted with a signature - no need to match all the constructors.
class SummaryModelTest extends SummaryModelCsv { | ||
override predicate row(string row) { | ||
row = | ||
[ | ||
//"package;type;overrides;name;signature;ext;inputspec;outputspec;kind", | ||
"generatedtest;Test;false;getMapKey;;;MapKey of Argument[0];ReturnValue;value", | ||
"generatedtest;Test;false;getMapValue;;;MapValue of Argument[0];ReturnValue;value" | ||
] | ||
} | ||
} |
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.
You should be able to rebase and remove this now.
467148d
to
d34602f
Compare
|
d34602f
to
d468388
Compare
|
This PR should be good to go now that my constructor PR is merged. |
Looks like there's a bad row somewhere:
|
java/ql/src/semmle/code/java/frameworks/spring/SpringWebUtil.qll
Outdated
Show resolved
Hide resolved
Oops, forgot to actually push the fixes. I missed the test generator error for that one, have now double checked. |
12ddb73
to
ebb87a0
Compare
java/ql/src/semmle/code/java/frameworks/spring/SpringWebUtil.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/spring/SpringWebUtil.qll
Outdated
Show resolved
Hide resolved
0ccfad7
to
9c35332
Compare
I've now actually added a test for the sanitizer and confirmed that at least the webutil test passes. This review cycle definitely shouldn't have happened, sorry. |
@@ -94,6 +94,8 @@ private class DefaultXssSink extends XssSink { | |||
private class DefaultXSSSanitizer extends XssSanitizer { | |||
DefaultXSSSanitizer() { | |||
this.getType() instanceof NumericType or this.getType() instanceof BooleanType | |||
or | |||
this.asExpr().(MethodAccess).getMethod().getName().regexpMatch("(?i)html_?escape.*") |
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.
this.asExpr().(MethodAccess).getMethod().getName().regexpMatch("(?i)html_?escape.*") | |
// Match `org.springframework.web.util.HtmlUtils.htmlEscape` and possibly other methods like it. | |
this.asExpr().(MethodAccess).getMethod().getName().regexpMatch("(?i)html_?escape.*") |
"org.springframework.web.util;UriBuilder;true;queryParamIfPresent;;;Argument[0];Argument[-1];taint", | ||
"org.springframework.web.util;UriBuilder;true;queryParamIfPresent;;;Element of Argument[1];Argument[-1];taint", | ||
"org.springframework.web.util;UriBuilder;true;queryParams;;;Argument[-1];ReturnValue;value", | ||
"org.springframework.web.util;UriBuilder;true;queryParams;;;MapKey of Argument[0];SyntheticField[uri.Query] ofArgument[-1];taint", |
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.
Typo. This should be caught by our tests. If it isn't: find out why.
9c35332
to
627dbc0
Compare
javaGenerated file changes for java
- `Spring <https://spring.io/>`_,``org.springframework.*``,29,306,91,,,,19,14,,29
+ `Spring <https://spring.io/>`_,``org.springframework.*``,29,467,91,,,,19,14,,29
- Totals,,84,2705,398,13,6,6,107,33,1,66
+ Totals,,84,2866,398,13,6,6,107,33,1,66
+ org.springframework.web.util,,,161,,,,,,,,,,,,,,,,,,,136,25 |
Fixed. The reason the tests didn't catch it is threefold:
I also added tests for the HTML utility functions that I'd added models for. |
Co-Authored-By: Anders Schack-Mulligen <[email protected]>
627dbc0
to
814004e
Compare
javaGenerated file changes for java
- `Spring <https://spring.io/>`_,``org.springframework.*``,29,306,91,,,,19,14,,29
+ `Spring <https://spring.io/>`_,``org.springframework.*``,29,467,91,,,,19,14,,29
- Totals,,84,2711,398,13,6,6,107,33,1,66
+ Totals,,84,2872,398,13,6,6,107,33,1,66
+ org.springframework.web.util,,,161,,,,,,,,,,,,,,,,,,,136,25 |
"org.springframework.web.util;UriTemplateHandler;true;expand;;;Argument[-1..0];ReturnValue;taint", | ||
"org.springframework.web.util;UriTemplateHandler;true;expand;(String,Map);;MapValue of Argument[1];ReturnValue;taint", | ||
"org.springframework.web.util;UriTemplateHandler;true;expand;(String,Object[]);;ArrayElement of Argument[1];ReturnValue;taint", |
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.
These are defined on the abstract superclass too
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.
I assume you meant the DefaultUriBuilderFactory
models below; I've removed them.
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.
I meant they're specified by https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/AbstractUriTemplateHandler.html like getBaseUrl et al below, so should be modelled against it for consistency
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.
It seems to me like AbstractUriTemplateHandler
is an implementation of UriTemplateHandler
?
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.
Doh yes sorry, I read the class hierarchy backwards
javaGenerated file changes for java
- `Spring <https://spring.io/>`_,``org.springframework.*``,29,306,91,,,,19,14,,29
+ `Spring <https://spring.io/>`_,``org.springframework.*``,29,464,91,,,,19,14,,29
- Totals,,84,2711,398,13,6,6,107,33,1,66
+ Totals,,84,2869,398,13,6,6,107,33,1,66
+ org.springframework.web.util,,,158,,,,,,,,,,,,,,,,,,,133,25 |
"org.springframework.web.util;UriTemplateHandler;true;expand;;;Argument[-1..0];ReturnValue;taint", | ||
"org.springframework.web.util;UriTemplateHandler;true;expand;(String,Map);;MapValue of Argument[1];ReturnValue;taint", | ||
"org.springframework.web.util;UriTemplateHandler;true;expand;(String,Object[]);;ArrayElement of Argument[1];ReturnValue;taint", |
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.
I meant they're specified by https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/AbstractUriTemplateHandler.html like getBaseUrl et al below, so should be modelled against it for consistency
"org.springframework.web.util;ContentCachingRequestWrapper;false;ContentCachingRequestWrapper;;;Argument[0];Argument[-1];taint", | ||
"org.springframework.web.util;ContentCachingRequestWrapper;false;getContentAsByteArray;;;Argument[-1];ReturnValue;taint", | ||
"org.springframework.web.util;ContentCachingResponseWrapper;false;ContentCachingResponseWrapper;;;Argument[0];Argument[-1];taint", | ||
"org.springframework.web.util;ContentCachingResponseWrapper;false;getContentAsByteArray;;;Argument[-1];ReturnValue;taint", | ||
"org.springframework.web.util;ContentCachingResponseWrapper;false;getContentInputStream;;;Argument[-1];ReturnValue;taint", |
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.
Worth noting for a future task: we don't currently model the superclass javax.servlet.[Http]ServletResponseWrapper
"org.springframework.web.util;UriComponents;false;getScheme;;;Argument[-1];ReturnValue;taint", | ||
"org.springframework.web.util;UriComponents;false;getSchemeSpecificPart;;;Argument[-1];ReturnValue;taint", | ||
"org.springframework.web.util;UriComponents;false;getUserInfo;;;Argument[-1];ReturnValue;taint", | ||
"org.springframework.web.util;UriComponents;false;toUri;;;Argument[-1];ReturnValue;taint", |
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.
I think normalize
and toString
should both be taint propagating here
"org.springframework.web.util;UriTemplate;false;expand;(Map);;MapValue of Argument[0];ReturnValue;taint", | ||
"org.springframework.web.util;UriTemplate;false;expand;(Object[]);;ArrayElement of Argument[0];ReturnValue;taint", | ||
"org.springframework.web.util;UriTemplate;false;getVariableNames;;;Argument[-1];Element of ReturnValue;taint", | ||
"org.springframework.web.util;UriTemplate;false;match;;;Argument[0];MapValue of ReturnValue;taint", |
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.
to check: probably has a taint-propagating toString?
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.
toString
returns the template, so I would assume yes.
"org.springframework.web.util;UrlPathHelper;false;getOriginatingQueryString;;;Argument[0];ReturnValue;taint", | ||
"org.springframework.web.util;UrlPathHelper;false;getOriginatingRequestUri;;;Argument[0];ReturnValue;taint", | ||
"org.springframework.web.util;UrlPathHelper;false;getOriginatingServletPath;;;Argument[0];ReturnValue;taint", | ||
"org.springframework.web.util;UrlPathHelper;false;getRequestUri;;;Argument[0];ReturnValue;taint", |
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.
I think getPathWithinServletMapping etc are taint propagating (sounds like if you servlet is mounted at a
and the user requested a/b
then that would yield /b
?) I'd appreciate a once-over from someone who knows their servlets though regarding which of these methods in practice yields developer/admin-specified config information and which yield user/remote-specified data.
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.
This sounds right to me.
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.
I've removed getOriginatingServletPath
since that seems like it would be admin-specified.
"org.springframework.web.util;WebUtils;false;getRequiredSessionAttribute;;;Argument[0];ReturnValue;taint", | ||
"org.springframework.web.util;WebUtils;false;getSessionAttribute;;;Argument[0];ReturnValue;taint", | ||
"org.springframework.web.util;WebUtils;false;parseMatrixVariables;;;Argument[0];MapKey of ReturnValue;taint", | ||
"org.springframework.web.util;WebUtils;false;parseMatrixVariables;;;Argument[0];MapValue of ReturnValue;taint" |
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.
Model setters?
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.
I'm unsure why I didn't model the session variable setter, but I excluded the system property setter because it doesn't seem easily modelable.
javaGenerated file changes for java
- `Spring <https://spring.io/>`_,``org.springframework.*``,29,306,91,,,,19,14,,29
+ `Spring <https://spring.io/>`_,``org.springframework.*``,29,469,91,,,,19,14,,29
- Totals,,84,2711,398,13,6,6,107,33,1,66
+ Totals,,84,2874,398,13,6,6,107,33,1,66
+ org.springframework.web.util,,,163,,,,,,,,,,,,,,,,,,,138,25 |
No description provided.