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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: majorAnalysis
---
* Added new XSS sink where `InnerHTML` is assigned to with the Angular Renderer2 API
Original file line number Diff line number Diff line change
Expand Up @@ -1032,3 +1032,35 @@ private class BindCall extends DataFlow::PartialInvokeNode::Range, DataFlow::Cal
result = this.getArgument(0)
}
}

/**
* A DOM attribute write, using the AngularJS Renderer2 API: a call to `Renderer2.setProperty`.
*/
private class AngularRenderer2AttributeDefinition extends DOM::AttributeDefinition {
DataFlow::Node propertyNode;
DataFlow::Node valueNode;
DataFlow::Node elementNode;

AngularRenderer2AttributeDefinition() {
exists(API::CallNode setProperty |
setProperty =
API::moduleImport("@angular/core")
.getMember("Renderer2")
.getInstance()
.getMember("setProperty")
.getACall() and
elementNode = setProperty.getArgument(0) and
propertyNode = setProperty.getArgument(1) and
valueNode = setProperty.getArgument(2) and
this = setProperty.asExpr()
)
}

override string getName() { result = propertyNode.getStringValue() }

// override DOM::ElementDefinition getElement() { /* TODO */ }
DataFlow::Node getElementNode() { result = elementNode }

override DataFlow::Node getValueNode() { result = valueNode }
//override predicate mayHaveTemplateValue() { /* TODO */ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,26 @@ module DomBasedXss {
}
}

// /**
// * A write to the `innerHTML` property of a DOM element, viewed as an XSS sink.
// *
// * Uses the Angular Renderer2 API, instead of the default `Element.innerHTML` property.
// */
// class AngularRender2SetPropertyInnerHtmlSink extends Sink {
// AngularRender2SetPropertyInnerHtmlSink() {
// exists(API::CallNode setProperty |
// setProperty =
// API::moduleImport("@angular/core")
// .getMember("Renderer2")
// .getInstance()
// .getMember("setProperty")
// .getACall() and
// this = setProperty.getParameter(2).asSink() and
// setProperty.getArgument(1).getStringValue() = "innerHTML"
// )
// }
// }

/**
* A value being piped into the `safe` pipe in a template file,
* disabling subsequent HTML escaping.
Expand Down
Loading