JS: fix ql/field-only-used-in-charpred within JavaScript

This commit is contained in:
Erik Krogh Kristensen
2022-01-14 10:32:14 +01:00
parent 3d3c6875a6
commit b8f1fb3954
30 changed files with 147 additions and 181 deletions

View File

@@ -2,14 +2,11 @@ import javascript
import semmle.javascript.dataflow.InferredTypes
import semmle.javascript.dataflow.CustomAbstractValueDefinitions
class MyCustomAbstractValueDefinition extends CustomAbstractValueDefinition {
DataFlow::ValueNode node;
class MyCustomAbstractValueDefinition extends CustomAbstractValueDefinition, AST::ValueNode {
MyCustomAbstractValueDefinition() {
DataFlow::valueNode(this) = node and
node instanceof DataFlow::ObjectLiteralNode and
this.flow() instanceof DataFlow::ObjectLiteralNode and
exists(DataFlow::PropWrite pwn |
pwn.writes(node, "custom", any(BooleanLiteral l | l.getValue() = "true").flow())
pwn.writes(this.flow(), "custom", any(BooleanLiteral l | l.getValue() = "true").flow())
)
}

View File

@@ -11,17 +11,17 @@ abstract class Violation extends ASTNode {
* The assertion holds if `name1 = name2`, indicating that `X` resolved to the right interface.
*/
class TypeResolutionAssertion extends TupleTypeExpr, Violation {
InterfaceDeclaration interface;
LocalTypeAccess typeAccess;
string expected;
string actual;
TypeResolutionAssertion() {
typeAccess = getElementType(0) and
expected = getElementType(1).(StringLiteralTypeExpr).getValue() and
typeAccess.getLocalTypeName() = interface.getIdentifier().(TypeDecl).getLocalTypeName() and
actual = interface.getField("where").getTypeAnnotation().(StringLiteralTypeExpr).getValue() and
actual != expected
exists(InterfaceDeclaration interface, LocalTypeAccess typeAccess |
typeAccess = getElementType(0) and
expected = getElementType(1).(StringLiteralTypeExpr).getValue() and
typeAccess.getLocalTypeName() = interface.getIdentifier().(TypeDecl).getLocalTypeName() and
actual = interface.getField("where").getTypeAnnotation().(StringLiteralTypeExpr).getValue() and
actual != expected
)
}
override string reason() {

View File

@@ -23,9 +23,7 @@ class ApiObject extends DataFlow::NewNode {
}
class Connection extends DataFlow::SourceNode {
ApiObject api;
Connection() { this = api.ref().getAMethodCall("createConnection") }
Connection() { this = any(ApiObject api).ref().getAMethodCall("createConnection") }
DataFlow::SourceNode ref(DataFlow::TypeTracker t) {
t.start() and
@@ -49,9 +47,7 @@ class Connection extends DataFlow::SourceNode {
}
class DataValue extends DataFlow::SourceNode {
Connection connection;
DataValue() { this = connection.getACallback().getParameter(0) }
DataValue() { this = any(Connection connection).getACallback().getParameter(0) }
DataFlow::SourceNode ref(DataFlow::TypeTracker t) {
t.start() and