Skip to content

Conversation

@smowton
Copy link
Contributor

@smowton smowton commented Jun 25, 2021

This matches https://github.com/github/codeql-securitylab/blob/main/java/ql/src/pwntester/security/RestXSS.ql in terms of tracking content-types in order to sanitize or sink entity bodies:

  • ResponseBuilders and related types with a specified content-type are followed forwards to find entities that have a known good or bad type, and are sanitized or sunk (with a barrier to avoid a duplicate hit) respectively
  • Those that can't be conclusively identified either way are followed through to a resource method return site as before (this means the sink location varies depending on whether the content-type is set explicitly or by an annotation)
  • With slightly more restricted logic, entities are followed forward to find a dangerous future content-type setting
@smowton smowton requested a review from a team as a code owner June 25, 2021 17:13
@smowton smowton force-pushed the smowton/feature/jax-rs-content-type-sensitivity-fixes branch from 506780a to 5849e8b Compare June 28, 2021 18:39
smowton added 7 commits June 30, 2021 12:04
Also extend the routine slightly to expose multiple content types given with array notation
This follows content-type specifications across Variant-related functions and the ResponseBuilder class in order to sanitize or sink entities as appropriate.
* Expose getContentTypeString for use by tests
* Use it to get constant arguments to @produces annotations
* Note that text/html is xss-vulnerable (I have no idea how it ever came to expect exactly text/plain)
@smowton smowton force-pushed the smowton/feature/jax-rs-content-type-sensitivity-fixes branch from 7d76e55 to 7f556de Compare June 30, 2021 11:04
@smowton
Copy link
Contributor Author

smowton commented Jun 30, 2021

Rebased now that the corresponding tests have landed.

// e.g. MediaType.TEXT_PLAIN => text/plain
result = jaxMediaType.getName().toLowerCase().replaceAll("_", "/")
Expr getADeclaredContentTypeExpr() {
(
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop superfluous parens.

* This could be an instance of `Response.ResponseBuilder`, `Variant`, `Variant.VariantListBuilder` or
* a `List<Variant>`.
*
* This routine is used to search forwards for response entities set after the content-type is configured.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/routine/predicate/ ?

)
or
// Recursive case: ordinary local dataflow
DataFlow::localFlow(getABuilderWithExplicitContentType(contentType), result)
Copy link
Contributor

Choose a reason for hiding this comment

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

Replacing this with DataFlow::localFlowStep might yield better performance and the semantics should be the same, since this is already being transitively closed. Could you perhaps check whether you can observe a difference?

Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

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

Some inline comments, otherwise looks ok to me.

@smowton
Copy link
Contributor Author

smowton commented Aug 3, 2021

@aschackmull suggestions applied

@smowton smowton merged commit eaf3d3c into github:main Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants