Skip to content

Commit 5ad18eb

Browse files
committed
C++: Add ExternalAPI query files (for AST and IR).
1 parent 057bb14 commit 5ad18eb

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Frequency counts for external APIs that are used with untrusted data
3+
* @description This reports the external APIs that are used with untrusted data, along with how
4+
* frequently the API is called, and how many unique sources of untrusted data flow
5+
* to it.
6+
* @id cpp/count-untrusted-data-external-api
7+
* @kind table
8+
* @tags security external/cwe/cwe-20
9+
*/
10+
11+
import cpp
12+
import semmle.code.cpp.security.ExternalAPIs
13+
14+
from ExternalAPIUsedWithUntrustedData externalAPI
15+
select externalAPI, count(externalAPI.getUntrustedDataNode()) as numberOfUses,
16+
externalAPI.getNumberOfUntrustedSources() as numberOfUntrustedSources order by
17+
numberOfUntrustedSources desc
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Frequency counts for external APIs that are used with untrusted data
3+
* @description This reports the external APIs that are used with untrusted data, along with how
4+
* frequently the API is called, and how many unique sources of untrusted data flow
5+
* to it.
6+
* @id cpp/count-untrusted-data-external-api-ir
7+
* @kind table
8+
* @tags security external/cwe/cwe-20
9+
*/
10+
11+
import cpp
12+
import semmle.code.cpp.security.ir.ExternalAPIs
13+
14+
from ExternalAPIUsedWithUntrustedData externalAPI
15+
select externalAPI, count(externalAPI.getUntrustedDataNode()) as numberOfUses,
16+
externalAPI.getNumberOfUntrustedSources() as numberOfUntrustedSources order by
17+
numberOfUntrustedSources desc
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Untrusted data passed to external API
3+
* @description Data provided remotely is used in this external API without sanitization, which could be a security risk.
4+
* @id cpp/untrusted-data-to-external-api-ir
5+
* @kind path-problem
6+
* @precision low
7+
* @problem.severity error
8+
* @tags security external/cwe/cwe-20
9+
*/
10+
11+
import cpp
12+
import semmle.code.cpp.ir.dataflow.TaintTracking
13+
import semmle.code.cpp.security.ir.ExternalAPIs
14+
import DataFlow::PathGraph
15+
16+
from UntrustedDataToExternalAPIConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
17+
where config.hasFlowPath(source, sink)
18+
select sink, source, sink,
19+
"Call to " + sink.getNode().(ExternalAPIDataNode).getExternalFunction().toString() +
20+
" with untrusted data from $@.", source, source.toString()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Untrusted data passed to external API
3+
* @description Data provided remotely is used in this external API without sanitization, which could be a security risk.
4+
* @id cpp/untrusted-data-to-external-api
5+
* @kind path-problem
6+
* @precision low
7+
* @problem.severity error
8+
* @tags security external/cwe/cwe-20
9+
*/
10+
11+
import cpp
12+
import semmle.code.cpp.dataflow.TaintTracking
13+
import semmle.code.cpp.security.ExternalAPIs
14+
import DataFlow::PathGraph
15+
16+
from UntrustedDataToExternalAPIConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
17+
where config.hasFlowPath(source, sink)
18+
select sink, source, sink,
19+
"Call to " + sink.getNode().(ExternalAPIDataNode).getExternalFunction().toString() +
20+
" with untrusted data from $@.", source, source.toString()

0 commit comments

Comments
 (0)