-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18466 from asgerf/js/view-component-inputs
JS: Add view-component-input threat model
- Loading branch information
Showing
34 changed files
with
407 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
javascript/ql/lib/semmle/javascript/ViewComponentInput.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Provides a classes and predicates for contributing to the `view-component-input` threat model. | ||
*/ | ||
|
||
private import javascript | ||
|
||
/** | ||
* An input to a view component, such as React props. | ||
*/ | ||
abstract class ViewComponentInput extends DataFlow::Node { | ||
/** Gets a string that describes the type of this threat-model source. */ | ||
abstract string getSourceType(); | ||
} | ||
|
||
private class ViewComponentInputAsThreatModelSource extends ThreatModelSource::Range instanceof ViewComponentInput | ||
{ | ||
ViewComponentInputAsThreatModelSource() { not isSafeType(this.asExpr().getType()) } | ||
|
||
final override string getThreatModel() { result = "view-component-input" } | ||
|
||
final override string getSourceType() { result = ViewComponentInput.super.getSourceType() } | ||
} | ||
|
||
private predicate isSafeType(Type t) { | ||
t instanceof NumberLikeType | ||
or | ||
t instanceof BooleanLikeType | ||
or | ||
t instanceof UndefinedType | ||
or | ||
t instanceof NullType | ||
or | ||
t instanceof VoidType | ||
or | ||
hasSafeTypes(t, t.(UnionType).getNumElementType()) | ||
or | ||
isSafeType(t.(IntersectionType).getAnElementType()) | ||
} | ||
|
||
/** Hold if the first `n` components of `t` are safe types. */ | ||
private predicate hasSafeTypes(UnionType t, int n) { | ||
isSafeType(t.getElementType(0)) and | ||
n = 1 | ||
or | ||
isSafeType(t.getElementType(n - 1)) and | ||
hasSafeTypes(t, n - 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
javascript/ql/src/change-notes/2025-01-22-view-component-inputs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.