only flag React elements in ClientSideUrlRedirect if it's a HTML element, or known link class

This commit is contained in:
Erik Krogh Kristensen
2021-02-17 13:59:19 +01:00
parent 36049f05f8
commit ecccb8a409
4 changed files with 29 additions and 2 deletions

View File

@@ -65,6 +65,12 @@ class JSXElement extends JSXNode {
}
override string getAPrimaryQlClass() { result = "JSXElement" }
/**
* Holds if this JSX element is a HTML element.
* That is, the name starts with a lowercase letter.
*/
predicate isHTMLElement() { getName().regexpMatch("[a-z].*") }
}
/**

View File

@@ -173,7 +173,10 @@ module ClientSideUrlRedirect {
class ReactAttributeWriteUrlSink extends ScriptUrlSink {
ReactAttributeWriteUrlSink() {
exists(JSXAttribute attr |
attr.getName() = DOM::getAPropertyNameInterpretedAsJavaScriptUrl()
attr.getName() = DOM::getAPropertyNameInterpretedAsJavaScriptUrl() and
attr.getElement().isHTMLElement()
or
DataFlow::moduleImport("next/link").flowsToExpr(attr.getElement().getNameExpr())
|
this = attr.getValue().flow()
)