-
Notifications
You must be signed in to change notification settings - Fork 9
Add YAML Configurations for Security Rules Against File Access Vulnerabilities #47
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
rules/swift/security/swift-webview-config-allows-file-access-swift.yml
This file contains hidden or 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,48 @@ | ||
id: swift-webview-config-allows-file-access-swift | ||
language: swift | ||
severity: warning | ||
message: >- | ||
Webviews were observed that do not disable access to application files. | ||
If the WebView does not require loading content from the local filesystem | ||
of the application, this setting should be disabled. | ||
note: >- | ||
[CWE-272]: Least Privilege Violation | ||
[REFERENCES] | ||
https://mas.owasp.org/MASVS/controls/MASVS-PLATFORM-2/ | ||
utils: | ||
match_call_expression: | ||
kind: call_expression | ||
has: | ||
stopBy: end | ||
kind: call_suffix | ||
has: | ||
stopBy: end | ||
kind: value_arguments | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: value_argument | ||
has: | ||
stopBy: end | ||
kind: boolean_literal | ||
field: value | ||
regex: "^true$" | ||
- has: | ||
stopBy: end | ||
kind: value_argument | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: simple_identifier | ||
regex: "^forKey$" | ||
- has: | ||
stopBy: end | ||
kind: line_string_literal | ||
has: | ||
stopBy: end | ||
kind: line_str_text | ||
regex: "^allowFileAccessFromFileURLs$" | ||
|
||
rule: | ||
any: | ||
- matches: match_call_expression |
This file contains hidden or 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,114 @@ | ||
id: swift-xxe-prevention-swift | ||
severity: warning | ||
language: swift | ||
message: >- | ||
Usage of Apple's native XML Parser was observed where the parser is | ||
explicitly instructed to resolve external entities. This can lead to XXE | ||
attacks if untrusted input is parsed. Consider disabling this | ||
functionality where feasible. | ||
note: >- | ||
[CWE-611] Improper Restriction of XML External Entity Reference. | ||
[REFERENCES] | ||
- https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/ValidatingInput.html | ||
- https://mas.owasp.org/MASVS/controls/MASVS-CODE-4/ | ||
- https://owasp.org/www-community/vulnerabilities/XML_External_Entity_(XXE)_Processing | ||
utils: | ||
match_pattern_upgradeKnownHostsToHTTPS: | ||
kind: assignment | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: directly_assignable_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: simple_identifier | ||
pattern: $F | ||
- has: | ||
stopBy: end | ||
kind: navigation_suffix | ||
has: | ||
stopBy: neighbor | ||
kind: simple_identifier | ||
regex: "^shouldResolveExternalEntities$" | ||
- has: | ||
stopBy: neighbor | ||
regex: "^=$" | ||
- has: | ||
stopBy: neighbor | ||
kind: boolean_literal | ||
regex: "^true$" | ||
- follows: | ||
stopBy: end | ||
kind: property_declaration | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: pattern | ||
has: | ||
stopBy: neighbor | ||
kind: simple_identifier | ||
pattern: $F | ||
- has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
pattern: XMLParser($$$) | ||
- not: | ||
follows: | ||
stopBy: end | ||
kind: assignment | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: directly_assignable_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: simple_identifier | ||
pattern: $F | ||
- has: | ||
stopBy: end | ||
kind: navigation_suffix | ||
has: | ||
stopBy: neighbor | ||
kind: simple_identifier | ||
regex: "^shouldResolveExternalEntities$" | ||
- has: | ||
stopBy: neighbor | ||
regex: "^=$" | ||
- has: | ||
stopBy: neighbor | ||
kind: boolean_literal | ||
regex: "^true$" | ||
- not: | ||
precedes: | ||
stopBy: end | ||
kind: assignment | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: directly_assignable_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: simple_identifier | ||
pattern: $F | ||
- has: | ||
stopBy: end | ||
kind: navigation_suffix | ||
has: | ||
stopBy: neighbor | ||
kind: simple_identifier | ||
regex: "^shouldResolveExternalEntities$" | ||
- has: | ||
stopBy: neighbor | ||
regex: "^=$" | ||
- has: | ||
stopBy: neighbor | ||
any: | ||
- has: | ||
stopBy: neighbor | ||
pattern: $$$ | ||
rule: | ||
kind: assignment | ||
matches: match_pattern_upgradeKnownHostsToHTTPS |
122 changes: 122 additions & 0 deletions
122
tests/__snapshots__/swift-webview-config-allows-file-access-swift-snapshot.yml
This file contains hidden or 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,122 @@ | ||
id: swift-webview-config-allows-file-access-swift | ||
snapshots: | ||
? | | ||
func enableFileAccessFromFileURLs() { | ||
webView.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs") | ||
print("allowFileAccessFromFileURLs has been set to true.") | ||
} | ||
: labels: | ||
- source: 'webView.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: primary | ||
start: 38 | ||
end: 125 | ||
- source: 'true' | ||
style: secondary | ||
start: 81 | ||
end: 85 | ||
- source: 'true' | ||
style: secondary | ||
start: 81 | ||
end: 85 | ||
- source: forKey | ||
style: secondary | ||
start: 87 | ||
end: 93 | ||
- source: allowFileAccessFromFileURLs | ||
style: secondary | ||
start: 96 | ||
end: 123 | ||
- source: '"allowFileAccessFromFileURLs"' | ||
style: secondary | ||
start: 95 | ||
end: 124 | ||
- source: 'forKey: "allowFileAccessFromFileURLs"' | ||
style: secondary | ||
start: 87 | ||
end: 124 | ||
- source: '(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: secondary | ||
start: 80 | ||
end: 125 | ||
- source: '(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: secondary | ||
start: 80 | ||
end: 125 | ||
? | | ||
preferences.setValue(true, forKey: "allowFileAccessFromFileURLs") | ||
: labels: | ||
- source: 'preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: primary | ||
start: 0 | ||
end: 65 | ||
- source: 'true' | ||
style: secondary | ||
start: 21 | ||
end: 25 | ||
- source: 'true' | ||
style: secondary | ||
start: 21 | ||
end: 25 | ||
- source: forKey | ||
style: secondary | ||
start: 27 | ||
end: 33 | ||
- source: allowFileAccessFromFileURLs | ||
style: secondary | ||
start: 36 | ||
end: 63 | ||
- source: '"allowFileAccessFromFileURLs"' | ||
style: secondary | ||
start: 35 | ||
end: 64 | ||
- source: 'forKey: "allowFileAccessFromFileURLs"' | ||
style: secondary | ||
start: 27 | ||
end: 64 | ||
- source: '(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: secondary | ||
start: 20 | ||
end: 65 | ||
- source: '(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: secondary | ||
start: 20 | ||
end: 65 | ||
? | | ||
webViewConfig.webView.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs") | ||
: labels: | ||
- source: 'webViewConfig.webView.configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: primary | ||
start: 0 | ||
end: 101 | ||
- source: 'true' | ||
style: secondary | ||
start: 57 | ||
end: 61 | ||
- source: 'true' | ||
style: secondary | ||
start: 57 | ||
end: 61 | ||
- source: forKey | ||
style: secondary | ||
start: 63 | ||
end: 69 | ||
- source: allowFileAccessFromFileURLs | ||
style: secondary | ||
start: 72 | ||
end: 99 | ||
- source: '"allowFileAccessFromFileURLs"' | ||
style: secondary | ||
start: 71 | ||
end: 100 | ||
- source: 'forKey: "allowFileAccessFromFileURLs"' | ||
style: secondary | ||
start: 63 | ||
end: 100 | ||
- source: '(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: secondary | ||
start: 56 | ||
end: 101 | ||
- source: '(true, forKey: "allowFileAccessFromFileURLs")' | ||
style: secondary | ||
start: 56 | ||
end: 101 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.