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 16 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
32 changes: 32 additions & 0 deletions javascript/ql/lib/semmle/javascript/frameworks/Angular2.qll
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,36 @@
this = API::Node::ofType("@angular/core", "ElementRef").getMember("nativeElement").asSource()
}
}

/**
* A DOM attribute write, using the AngularJS Renderer2 API: a call to `Renderer2.setProperty`.
*/
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 }

Check warning on line 584 in javascript/ql/lib/semmle/javascript/frameworks/Angular2.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for member-predicate Angular2::Angular2::AngularRenderer2AttributeDefinition::getElementNode/0

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,20 @@ module DomBasedXss {
}
}

/**
* A write to the `innerHTML` or `outerHTML` property of a DOM element, viewed as an XSS sink.
*
* Uses the Angular Renderer2 API, instead of the default `Element.innerHTML` property.
*/
class AngularRender2SetPropertyInnerHtmlSink2 extends Sink {
AngularRender2SetPropertyInnerHtmlSink2() {
exists(Angular2::AngularRenderer2AttributeDefinition attrDef |
attrDef.getName() = ["innerHTML", "outerHTML"] and
this = attrDef.getValueNode()
)
}
}

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