-
Notifications
You must be signed in to change notification settings - Fork 9
Add new security rules for Swift applications regarding webviews and XML parsing #85
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
110 changes: 110 additions & 0 deletions
110
rules/swift/security/swift-webview-config-allows-js-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,110 @@ | ||
id: swift-webview-config-allows-js-swift | ||
severity: warning | ||
language: swift | ||
message: >- | ||
Webviews were observed that do not have JavaScript disabled. Consider | ||
disabling JavaScript wherever the functionality is not required, following | ||
the principle of least privelege. | ||
note: >- | ||
[CWE-272] Least Privilege Violation. | ||
[REFERENCES] | ||
- https://mas.owasp.org/MASVS/controls/MASVS-PLATFORM-2/ | ||
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: '^javaScriptEnabled|allowsContentJavaScript$' | ||
- 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 | ||
any: | ||
- pattern: WKWebpagePreferences() | ||
- pattern: WKPreferences() | ||
- not: | ||
follows: | ||
stopBy: neighbor | ||
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: '^(javaScriptEnabled|allowsContentJavaScript)$' | ||
- 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: '^(javaScriptEnabled|allowsContentJavaScript)$' | ||
- has: | ||
stopBy: neighbor | ||
regex: '^=$' | ||
- has: | ||
stopBy: neighbor | ||
pattern: $$$ | ||
rule: | ||
kind: assignment | ||
matches: match_pattern_upgradeKnownHostsToHTTPS |
73 changes: 73 additions & 0 deletions
73
rules/swift/security/swift-webview-config-base-url-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,73 @@ | ||
id: swift-webview-config-base-url-swift | ||
severity: warning | ||
language: swift | ||
message: >- | ||
UIWebView instances were observed where the baseURL is misconfigured as | ||
nil, which allows for origin abuse within the webview. In order to remove | ||
the effective origin, the application should explicitly set the baseURL to | ||
`about:blank` or similar. | ||
note: >- | ||
[CWE-272] Least Privilege Violation. | ||
[REFERENCES] | ||
- https://mas.owasp.org/MASVS/controls/MASVS-PLATFORM-2/ | ||
utils: | ||
matches_patttern_loadHTMLString_&_load: | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: navigation_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: simple_identifier | ||
pattern: $W | ||
- has: | ||
stopBy: end | ||
kind: navigation_suffix | ||
has: | ||
stopBy: end | ||
kind: simple_identifier | ||
regex: '^loadHTMLString|load$' | ||
- has: | ||
stopBy: end | ||
kind: call_suffix | ||
has: | ||
stopBy: end | ||
kind: value_argument | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: simple_identifier | ||
regex: '^baseURL$' | ||
- has: | ||
stopBy: end | ||
regex: '^nil$' | ||
- inside: | ||
stopBy: end | ||
kind: source_file | ||
has: | ||
stopBy: end | ||
kind: property_declaration | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: pattern | ||
has: | ||
stopBy: neighbor | ||
kind: simple_identifier | ||
pattern: $W | ||
- has: | ||
stopBy: neighbor | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: simple_identifier | ||
regex: '^UIWebView$' | ||
- has: | ||
stopBy: neighbor | ||
kind: call_suffix | ||
rule: | ||
kind: call_expression | ||
matches: matches_patttern_loadHTMLString_&_load |
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 |
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.