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 5 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
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.getParameter(1).asSink().asExpr().(StringLiteral).getValue() = "innerHTML"
aegilops marked this conversation as resolved.
Show resolved Hide resolved
)
}
}

/**
* A value being piped into the `safe` pipe in a template file,
* disabling subsequent HTML escaping.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,39 @@

override string getSourceType() { result = ap.getSourceType() }
}

/**
* Angular @Input() decorator on a member declaration.
*/
Fixed Show fixed Hide fixed
class InputMember extends MemberDeclaration {
InputMember() {
exists(Decorator decorator, Expr expr |
decorator.getElement() = this and
decorator.getExpression() = expr and
expr.(CallExpr).getCallee().(VarRef).getName() = "Input"
)
}
}

/**
* Use of an Angular @Input() member, modelled as `InputMember`.
*/
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
class InputMemberUse extends DataFlow::Node {
InputMemberUse() {
exists(InputMember member, string memberName, ThisExpr ta, FieldAccess fa |
memberName = member.getName() and
fa.getBase() = ta and
fa.getPropertyName() = memberName and
this.asExpr() = fa
)
}
}

/**
* A remote flow source that is a member of an Angular component class.
*/
private class AngularInputUse extends RemoteFlowSource {
Fixed Show fixed Hide fixed
AngularInputUse() { this instanceof InputMemberUse }

override string getSourceType() { result = "Angular @Input()" }
}
Loading