mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
JS: fix ql/field-only-used-in-charpred within JavaScript
This commit is contained in:
@@ -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())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user