Exlucde environmental variables from default detection in regexp injection

This commit is contained in:
Napalys Klicius
2025-07-31 12:09:30 +02:00
parent 16e9e8e836
commit 5f538209c9
3 changed files with 21 additions and 11 deletions

View File

@@ -5,6 +5,7 @@
*/
import javascript
private import codeql.threatmodels.ThreatModels
module RegExpInjection {
/**
@@ -32,19 +33,32 @@ module RegExpInjection {
/**
* An active threat-model source, considered as a flow source.
* Excludes environment variables by default - they require the "environment" threat model.
*/
private class ActiveThreatModelSourceAsSource extends Source instanceof ActiveThreatModelSource {
ActiveThreatModelSourceAsSource() { not this.isClientSideSource() }
ActiveThreatModelSourceAsSource() {
not this.isClientSideSource() and
not this.(ThreatModelSource).getThreatModel() = "environment"
}
}
private import IndirectCommandInjectionCustomizations
/**
* Environment variables as a source when the "environment" threat model is active.
*/
private class EnvironmentVariableAsSource extends Source instanceof ThreatModelSource {
EnvironmentVariableAsSource() {
this.getThreatModel() = "environment" and
currentThreatModel("environment")
}
override string describe() { result = "environment variable" }
}
/**
* A read of `process.env`, `process.argv`, and similar, considered as a flow source for regular
* expression injection.
* Command line arguments as a source for regular expression injection.
*/
class ArgvAsSource extends Source instanceof IndirectCommandInjection::Source {
override string describe() { result = IndirectCommandInjection::Source.super.describe() }
private class CommandLineArgumentAsSource extends Source instanceof CommandLineArguments {
override string describe() { result = "command-line argument" }
}
/**