Compare commits

...

1 Commits

Author SHA1 Message Date
Esben Sparre Andreasen
63de4ba939 boost StoredXssATM (automatically with tb boost) 2022-01-21 14:44:10 +01:00
3 changed files with 110 additions and 1 deletions

View File

@@ -10,7 +10,8 @@ newtype TEndpointType =
TXssSinkType() or
TNosqlInjectionSinkType() or
TSqlInjectionSinkType() or
TTaintedPathSinkType()
TTaintedPathSinkType() or
TStoredXssSinkType()
/** A class that can be predicted by endpoint scoring models. */
abstract class EndpointType extends TEndpointType {
@@ -55,3 +56,10 @@ class TaintedPathSinkType extends EndpointType, TTaintedPathSinkType {
override int getEncoding() { result = 4 }
}
/** The `StoredXssSinkType` class that can be predicted by endpoint scoring models. */
class StoredXssSinkType extends EndpointType, TStoredXssSinkType {
override string getDescription() { result = "StoredXssSink" }
override int getEncoding() { result = 5 }
}

View File

@@ -0,0 +1,72 @@
/**
* Provides a taint-tracking configuration for reasoning about stored
* cross-site scripting vulnerabilities.
* Is boosted by ATM.
*/
import javascript
import AdaptiveThreatModeling
import semmle.javascript.security.dataflow.Xss::StoredXss
/**
* This module provides logic to filter candidate sinks to those which are likely XSS sinks.
*/
module SinkEndpointFilter {
private import StandardEndpointFilters as StandardEndpointFilters
/**
* Provides a set of reasons why a given data flow node should be excluded as a sink candidate.
*
* If this predicate has no results for a sink candidate `n`, then we should treat `n` as an
* effective sink.
*/
string getAReasonSinkExcluded(DataFlow::Node sinkCandidate) {
result = StandardEndpointFilters::getAReasonSinkExcluded(sinkCandidate)
}
}
class StoredXssATMConfig extends ATMConfig {
StoredXssATMConfig() { this = "StoredXssATMConfig" }
override predicate isKnownSource(DataFlow::Node source) { source instanceof Source }
override predicate isKnownSink(DataFlow::Node sink) { sink instanceof Sink }
override predicate isEffectiveSink(DataFlow::Node sinkCandidate) {
not exists(SinkEndpointFilter::getAReasonSinkExcluded(sinkCandidate))
}
override EndpointType getASinkEndpointType() { result instanceof StoredXssSinkType }
}
/**
* A taint-tracking configuration for reasoning about XSS.
*/
class Configuration extends TaintTracking::Configuration {
Configuration() { this = "StoredXssATMConfig" }
override predicate isSource(DataFlow::Node source) { source instanceof Source }
override predicate isSink(DataFlow::Node sink) {
(sink instanceof Sink or any(StoredXssATMConfig cfg).isEffectiveSink(sink))
}
override predicate isSanitizer(DataFlow::Node node) {
super.isSanitizer(node) or
node instanceof Sanitizer
}
override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode guard) {
guard instanceof SanitizerGuard
}
}
/** A file name, considered as a flow source for stored XSS. */
class FileNameSourceAsSource extends Source {
FileNameSourceAsSource() { this instanceof FileNameSource }
}
/** User-controlled torrent information, considered as a flow source for stored XSS. */
class UserControlledTorrentInfoAsSource extends Source {
UserControlledTorrentInfoAsSource() { this instanceof ParseTorrent::UserControlledTorrentInfo }
}

View File

@@ -0,0 +1,29 @@
/**
* For internal use only.
*
* @name Stored cross-site scripting (boosted)
* @description Using uncontrolled stored values in HTML allows for a stored cross-site scripting vulnerability.
* @kind path-problem
* @scored
* @problem.severity error
* @security-severity 6.1
* @id adaptive-threat-modeling/js/stored-xss
* @tags experimental experimental/atm security external/cwe/cwe-079 external/cwe/cwe-116
*/
import experimental.adaptivethreatmodeling.StoredXssATM
import ATM::ResultsInfo
import DataFlow::PathGraph
from
DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score,
string scoreString
where
cfg.hasFlowPath(source, sink) and
not isFlowLikelyInBaseQuery(source.getNode(), sink.getNode()) and
score = getScoreForFlow(source.getNode(), sink.getNode()) and
scoreString = getScoreStringForFlow(source.getNode(), sink.getNode())
select sink.getNode(), source, sink,
"[Score = " + scoreString + "] This may be a js/stored-xss result depending on $@ " +
getAdditionalAlertInfo(source.getNode(), sink.getNode()), source.getNode(),
"a user-provided value", score