Files
codeql/python/.vscode/ql.code-snippets
Rasmus Wriedt Larsen 0cdb5c48cf Python: Remove type-tracking snippets for framework modeling
We won't need these anymore, since we can now use API graphs
2021-02-17 13:14:23 +01:00

156 lines
4.9 KiB
Plaintext

{
// Place your python workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Has relative path": {
"scope": "ql",
"prefix": "has relative path",
"body": [
"exists($1.getLocation().getFile().getRelativePath())"
],
"description": "has relative path",
},
"Exists": {
"scope": "ql",
"prefix": "exists",
"body": [
"exists(${1:DataFlow::Node node} |",
" $2",
")"
],
"description": "Exists clause",
},
"Predicate": {
"scope": "ql",
"prefix": "predicate",
"body": [
"predicate ${1:isFoo}(${2:DataFlow::Node node}) {",
" ${3:any()}",
"}"
],
"description": "Predicate",
},
"Class": {
"scope": "ql",
"prefix": "class",
"body": [
"class ${1:MyClass} extends ${2:DataFlow::MethodCallNode} {",
" $1() { ${3:getMethodName() = \"foo\"} }",
"",
" DataFlow::Node ${4:getThing}() { result = ${5:getArgument(0)} }",
"}"
],
"description": "Class",
},
"Abstract class": {
"scope": "ql",
"prefix": "abstract class",
"body": [
"abstract class ${1:AdditionalThing} extends ${2:DataFlow::Node} {",
" abstract ${3:DataFlow::Node} ${4:getThing}($5);",
"}"
],
"description": "Class",
},
"Class::Range": {
"scope": "ql",
"prefix": "range class",
"body": [
"class ${1:MyClass} extends ${2:DataFlow::Node} {",
" $1::Range range;",
"",
" $1() { this = range }",
"",
" ${3:DataFlow::Node} ${4:getThing}() { result = range.$4() }",
"}",
"",
"module $1 {",
" abstract class Range extends $2 {",
" abstract $3 $4();",
" }",
"}",
],
"description": "Class with ::Range pattern",
},
"Class::Range delegate": {
"scope": "ql",
"prefix": "range delegate",
"body": [
"${1:DataFlow::Node} ${2:getThing}() { result = range.$2() }"
],
"description": "Predicate that delegates to range class",
},
"Type tracking predicate": {
"scope": "ql",
"prefix": "type tracking",
"body": [
"/** Gets a reference to ${3:a thing}. */",
"private DataFlow::LocalSourceNode ${1:myType}(DataFlow::TypeTracker t) {",
" t.start() and",
" result = ${2:value}",
" or",
" exists(DataFlow::TypeTracker t2 |",
" result = $1(t2).track(t2, t)",
" )",
"}",
"",
"/** Gets a reference to $3. */",
"DataFlow::Node $1() {",
" $1(DataFlow::TypeTracker::end()).flowsTo(result)",
"}"
],
"description": "Type tracking predicate",
},
"Taint tracking configuration": {
"scope": "ql",
"prefix": "taint tracking",
"body": [
"/** @kind path-problem */",
"import python",
"import experimental.dataflow.DataFlow",
"import experimental.dataflow.TaintTracking",
"import experimental.semmle.python.Concepts",
"import experimental.dataflow.RemoteFlowSources",
"import DataFlow::PathGraph",
"class ${1:Config} extends TaintTracking::Configuration {",
" $1() { this = \"$1\" } ",
"",
" override predicate isSource(DataFlow::Node node) {",
" ${2:none()}",
" }",
"",
" override predicate isSink(DataFlow::Node node) {",
" ${3:none()}",
" }",
"}",
"",
"from $1 cfg, DataFlow::PathNode source, DataFlow::PathNode sink",
"where cfg.hasFlowPath(source, sink)",
"select sink, source, sink, \"taint from $@\", source.getNode(), \"here\""
]
},
}