Skip to content

Add Browser Extensions Queries and Models #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions javascript/lib/browserextension/BothSidesRequestForgeryQuery.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Provides a taint-tracking configuration for reasoning about client-side
* request forgery.
*
* Note, for performance reasons: only import this file if
* the `Configuration` class is needed, otherwise
* `RequestForgeryCustomizations` should be imported instead.
*/

import javascript
import semmle.javascript.security.dataflow.UrlConcatenation
import semmle.javascript.security.dataflow.RequestForgeryCustomizations::RequestForgery
import BrowserAPI

/**
* A taint tracking configuration for client-side request forgery.
* Server side is disabled since this is in the browser, but the extra models can be enabled for extra coverage
*/
class Configuration extends TaintTracking::Configuration {
Configuration() { this = "ClientSideRequestForgery" }

override predicate isSource(DataFlow::Node source) {
exists(Source src |
source = src and
not src.isServerSide()
) or
source instanceof OnMessageExternal or source instanceof OnConnectExternal
}

override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

override predicate isSanitizer(DataFlow::Node node) {
super.isSanitizer(node) or
node instanceof Sanitizer
}

override predicate isSanitizerOut(DataFlow::Node node) { sanitizingPrefixEdge(node, _) }

override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
isAdditionalRequestForgeryStep(pred, succ)
}
}

class BrowserStep extends DataFlow::SharedFlowStep {
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
(exists (DataFlow::ParameterNode p |
pred instanceof SendMessage and
succ = p and
p.getParameter() instanceof AddListener
))
}
}

class ReturnStep extends DataFlow::SharedFlowStep {
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
(exists (DataFlow::ParameterNode p |
succ instanceof SendMessageReturnValue and
pred = p.getAnInvocation().getArgument(0) and
p.getParameter() instanceof AddListenerReturn
))
}
}

class AwaitStep extends DataFlow::SharedFlowStep {
override predicate step(DataFlow::Node pred, DataFlow::Node succ){
succ.asExpr() instanceof AwaitExpr and pred.asExpr() = succ.asExpr().(AwaitExpr).getOperand()
}
}
Loading
Loading