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

Java: Add models for the Spring web.util package #5953

Merged
merged 11 commits into from
Aug 18, 2021

Conversation

sauyon
Copy link
Contributor

@sauyon sauyon commented May 25, 2021

No description provided.

@sauyon sauyon requested a review from a team as a code owner May 25, 2021 19:16
@sauyon sauyon marked this pull request as draft May 25, 2021 19:16
@github-actions github-actions bot added the Java label May 25, 2021
@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch from ae2f6ea to 0264aff Compare May 29, 2021 19:15
@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch from 0264aff to 1d6726a Compare July 14, 2021 12:24
@sauyon sauyon marked this pull request as ready for review July 14, 2021 12:26
@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch from 55ffef8 to 6b53162 Compare July 15, 2021 14:49
@github github deleted a comment from github-actions bot Jul 15, 2021
@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch 2 times, most recently from 34a36c4 to 3d9808b Compare July 15, 2021 16:16
@github github deleted a comment from github-actions bot Jul 15, 2021
@github github deleted a comment from github-actions bot Jul 15, 2021
@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The differences can be found in the comparison artifact of this workflow run.

Comment on lines 135 to 136
"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",
Copy link
Contributor

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.

Comment on lines 7 to 16
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"
]
}
}
Copy link
Contributor

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.

@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch 2 times, most recently from 467148d to d34602f Compare July 22, 2021 14:23
@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The differences can be found in the comparison artifact of this workflow run.

@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch from d34602f to d468388 Compare July 22, 2021 15:34
@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The differences can be found in the comparison artifact of this workflow run.

@sauyon
Copy link
Contributor Author

sauyon commented Jul 22, 2021

This PR should be good to go now that my constructor PR is merged.

@aschackmull
Copy link
Contributor

Looks like there's a bad row somewhere:

 invalidModelRow
+| Wrong number of columns in summary model row, expected 9, got 10. |

@sauyon
Copy link
Contributor Author

sauyon commented Jul 26, 2021

Oops, forgot to actually push the fixes. I missed the test generator error for that one, have now double checked.

@github github deleted a comment from github-actions bot Jul 27, 2021
@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch from 12ddb73 to ebb87a0 Compare July 27, 2021 04:55
@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch 2 times, most recently from 0ccfad7 to 9c35332 Compare August 4, 2021 09:38
@sauyon
Copy link
Contributor Author

sauyon commented Aug 4, 2021

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.*")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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",
Copy link
Contributor

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.

@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch from 9c35332 to 627dbc0 Compare August 8, 2021 21:46
@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2021

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    `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
  • Changes to framework-coverage-java.csv:
+ org.springframework.web.util,,,161,,,,,,,,,,,,,,,,,,,136,25

@sauyon
Copy link
Contributor Author

sauyon commented Aug 8, 2021

Fixed. The reason the tests didn't catch it is threefold:

  • The test generator generates tests for UriBuilder using UriComponentsBuilder,
  • I'd added redundant models for methods of UriComponentBuilder, and
  • the models for UriComponentBuilder applied to calls on UriBuilder, presumably because there was only one implementation of UriBuilder.

I also added tests for the HTML utility functions that I'd added models for.

@github github deleted a comment from github-actions bot Aug 8, 2021
@github github deleted a comment from github-actions bot Aug 8, 2021
@sauyon sauyon force-pushed the sauyon/java/spring-webutil branch from 627dbc0 to 814004e Compare August 12, 2021 18:20
@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    `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
  • Changes to framework-coverage-java.csv:
+ org.springframework.web.util,,,161,,,,,,,,,,,,,,,,,,,136,25

Comment on lines +52 to +54
"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",
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    `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
  • Changes to framework-coverage-java.csv:
+ org.springframework.web.util,,,158,,,,,,,,,,,,,,,,,,,133,25

Comment on lines +52 to +54
"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",
Copy link
Contributor

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

Comment on lines +59 to +63
"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",
Copy link
Contributor

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",
Copy link
Contributor

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",
Copy link
Contributor

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?

Copy link
Contributor Author

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",
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Model setters?

Copy link
Contributor Author

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.

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    `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
  • Changes to framework-coverage-java.csv:
+ org.springframework.web.util,,,163,,,,,,,,,,,,,,,,,,,138,25

@smowton smowton merged commit cc4fe73 into main Aug 18, 2021
@smowton smowton deleted the sauyon/java/spring-webutil branch August 18, 2021 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants