Merge pull request #18466 from asgerf/js/view-component-inputs

JS: Add view-component-input threat model
This commit is contained in:
Asger F
2025-01-24 10:59:25 +01:00
committed by GitHub
34 changed files with 407 additions and 66 deletions

View File

@@ -0,0 +1,7 @@
---
category: majorAnalysis
---
* Added a new threat model kind called `view-component-input`, which can enabled with [advanced setup](https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning#extending-codeql-coverage-with-threat-models).
When enabled, all React props, Vue props, and input fields in an Angular component are seen as taint sources, even if none of the corresponding instantiation sites appear to pass in a tainted value.
Some users may prefer this as a "defense in depth" option but note that it may result in false positives.
Regardless of whether the threat model is enabled, CodeQL will propagate taint from the instantiation sites of such components into the components themselves.

View File

@@ -11,13 +11,6 @@
import javascript
import meta.internal.TaintMetrics
string getName(DataFlow::Node node) {
result = node.(RemoteFlowSource).getSourceType()
or
not node instanceof RemoteFlowSource and
result = "Taint source"
}
from DataFlow::Node node
where node = relevantTaintSource()
select node, getName(node)
from ThreatModelSource node
where node = relevantTaintSource() and node.getThreatModel() = "remote"
select node, getTaintSourceName(node)

View File

@@ -0,0 +1,19 @@
/**
* @name Threat model sources
* @description Sources of possibly untrusted input that can be configured via threat models.
* @kind problem
* @problem.severity recommendation
* @id js/meta/alerts/threat-model-sources
* @tags meta
* @precision very-low
*/
import javascript
import meta.internal.TaintMetrics
from ThreatModelSource node, string threatModel
where
node = relevantTaintSource() and
threatModel = node.getThreatModel() and
threatModel != "remote" // "remote" is reported by TaintSources.ql
select node, getTaintSourceName(node) + " (\"" + threatModel + "\" threat model)"

View File

@@ -75,9 +75,9 @@ DataFlow::Node relevantTaintSink(string kind) {
DataFlow::Node relevantTaintSink() { result = relevantTaintSink(_) }
/**
* Gets a relevant remote flow source.
* Gets a relevant threat model source.
*/
RemoteFlowSource relevantTaintSource() { not result.getFile() instanceof IgnoredFile }
ThreatModelSource relevantTaintSource() { not result.getFile() instanceof IgnoredFile }
/**
* Gets the output of a call that shows intent to sanitize a value
@@ -100,3 +100,10 @@ DataFlow::Node relevantSanitizerInput() {
result = any(HtmlSanitizerCall call).getInput() and
not result.getFile() instanceof IgnoredFile
}
string getTaintSourceName(DataFlow::Node node) {
result = node.(ThreatModelSource).getSourceType()
or
not node instanceof ThreatModelSource and
result = "Taint source"
}