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

JavaScript CodeQL library updates: new Angular sink(s) #18397

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

aegilops
Copy link
Contributor

@aegilops aegilops commented Jan 3, 2025

Pull Request checklist

All query authors

Internal query authors only

  • Autofixes generated based on these changes are valid, only needed if this PR makes significant changes to .ql, .qll, or .qhelp files. See the documentation (internal access required).
  • Changes are validated at scale (internal access required).
  • Adding a new query? Consider also adding the query to autofix.

@github-actions github-actions bot added the JS label Jan 3, 2025
@aegilops
Copy link
Contributor Author

aegilops commented Jan 6, 2025

I'm wondering which other properties being set on elements might need to be treated as XSS sinks, so that I don't fix up just innerHTML.

I'll see if I can copy what's done in the existing library.

I'm thinking that a.href and script.src and object.src might need to be XSS sinks, but I don't want to have to think too hard about this and would prefer to just copy existing conclusions!

@asgerf
Copy link
Contributor

asgerf commented Jan 6, 2025

I'm wondering which other properties being set on elements might need to be treated as XSS sinks, so that I don't fix up just innerHTML.

You might be able to model this as an AttributeDefinition instead of directly as a sink. See D3.qll for a simple example.

@aegilops aegilops changed the title JavaScript CodeQL library updates: new Angular source and sink JavaScript CodeQL library updates: new Angular sink(s) Jan 6, 2025
@aegilops
Copy link
Contributor Author

aegilops commented Jan 6, 2025

I'm wondering which other properties being set on elements might need to be treated as XSS sinks, so that I don't fix up just innerHTML.

You might be able to model this as an AttributeDefinition instead of directly as a sink. See D3.qll for a simple example.

I'm not 100% sure how to implement this, but I had a go in AngularJSCore.qll, with AngularRenderer2AttributeDefinition.

I wasn't totally sure how to define getElement(), or if I needed it, or mayHaveTemplateValue(), so I left them undefined.

If I write a simple query to select dom-based XSS sinks, having removed my hardcoded definition of the Angular-Renderer2-innerHTML sink in DomBasedXssCustomizations.qll then I don't find the new sinks I'm hoping to find:

import javascript
import semmle.javascript.security.dataflow.DomBasedXssCustomizations::DomBasedXss

from Sink sink
select sink

I don't know which bit of the library uses the various AttributeDefinition classes to find DOM XSS sinks, so I'm not sure how to debug more precisely.

@asgerf
Copy link
Contributor

asgerf commented Jan 7, 2025

Sorry, you'll have to do both:

  • Contribute to AttributeDefinition
  • Contribute to DomBasedXssCustomizations::Sinks

The reason is that setAttribute("innerHTML", x) does not actually do anything when interacting with the DOM API directly, so AttributeDefinition does not give rise to HTML injection sinks. But it does give rise to a few others like src and event handlers.

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.

2 participants