Skip to content

Commit

Permalink
Add ios js inject rule
Browse files Browse the repository at this point in the history
  • Loading branch information
stoletheminerals committed Mar 22, 2024
1 parent 3653644 commit cbe9d76
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
25 changes: 25 additions & 0 deletions assets/semgrep_rules/client/brave-execute-script-ios.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import WebKit

let webView = WKWebView(frame: .zero)
// ruleid: brave-execute-script-ios
webView.evaluateJavaScript("document.title") { (result, error) in
if let result = result {
print("Title: \(result)")
} else if let error = error {
print("Evaluate error: \(error.localizedDescription)")
}
}
// ruleid: brave-execute-script-ios
try await webView.evaluateSafeJavaScriptThrowing(
functionName: "localStorage.setItem",
args: ["storageKey", "receipt"],
contentWorld: .defaultClient
)
// ruleid: brave-execute-script-ios
webView.evaluateSafeJavaScript(
functionName: "alert(123)",
contentWorld: .page
)
// ruleid: brave-execute-script-ios
let userScript = WKUserScript(source: "document.title = 'Test';", injectionTime: .atDocumentEnd, forMainFrameOnly: true)
webView.configuration.userContentController.addUserScript(userScript)
23 changes: 23 additions & 0 deletions assets/semgrep_rules/client/brave-execute-script-ios.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
rules:
- id: brave-execute-script-ios
metadata:
author: Artem Chaikin
references:
- https://github.com/brave/brave-browser/wiki/Security-reviews
source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/client/brave-execute-script-ios.yaml
assignees: stoletheminerals
message: |
$FUNC usages should be vet by the security-team.
References:
- https://github.com/brave/brave-browser/wiki/Security-reviews (point 13)
severity: INFO
languages:
- swift
patterns:
- pattern-either:
- pattern: $OBJ.$FUNC(...)
- pattern: $FUNC(...)
- metavariable-regex:
metavariable: $FUNC
regex: ^(WKUserScript|evaluateSafeJavaScriptThrowing|evaluateSafeJavaScript|evaluateJavaScript)$

0 comments on commit cbe9d76

Please sign in to comment.