Kingdom: Encapsulation

Encapsulation is about drawing strong boundaries. In a web browser that might mean ensuring that your mobile code cannot be abused by other mobile code. On the server it might mean differentiation between validated data and unvalidated data, between one user's data and another's, or between data users are allowed to see and data that they are not.

118 items found
Weaknesses
Abstract
Transferring values between localStorage and sessionStorage can expose sensitive information unwittingly.
Explanation
HTML5 provides localStorage and sessionStorage maps to allow developers to persist program values. The sessionStorage map provides storage for the invoking page and lasts only for the duration of the page instance and the immediate browser session. The localStorage map, however, provides storage that is accessible over multiple page instances and multiple browser instances. This functionality allows an application to persist and utilize the same information in multiple browser tabs or windows.

For example, a developer may wish to utilize multiple browsers tabs or instances in a travel application that wants to allow a user to open multiple tabs to compare accommodations while still maintaining the users original search criteria. In the traditional HTTP storage scenario, the user risks purchases and decisions made in one tab (and stored in the session or cookies) interfering with purchases in another tab.

With the ability to utilize user values across multiple browser tabs, developers must be careful not to move sensitive information from the sessionStorage scope to the localStorage or vice versa.

Example: The following example stores the credit card CCV information in the session to indicate that a user has already authorized the site to charge the card on file for a purchase. For each purchase attempt within the context of the browser tab, credit card approval is required. To avoid the CCV being entered again, the information is stored in the sessionStorage object. However, the developer also stores the information within the localStorage object.


...
try {
sessionStorage.setItem("userCCV", currentCCV);
} catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
alert('Quota exceeded.');
}
}

...
...

var retrieveObject = sessionStorage.getItem("userCCV");
try {
localStorage.setItem("userCCV",retrieveObject);
} catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
alert('Quota exceeded.');
}
...

var userCCV = localStorage.getItem("userCCV");
...
}
...


By placing the information back into the localStorage object, the CCV information is now available in other browser tabs and also on new invocations of the browser. This will by-pass the application logic for the intended workflow.
desc.dataflow.javascript.cross_session_contamination
Abstract
The Visualforce page action method or controller constructor performs sensitive tasks without protection against unauthorized requests.
Explanation
A cross-site request forgery (CSRF) vulnerability occurs when:
1. A Web application uses session cookies.

2. The application acts on an HTTP request without verifying that the request was made with the user's consent.

By default, Visualforce pages are rendered with hidden form fields that serve as anti-CSRF tokens. These tokens are included in the requests that are sent from within the page, and the server checks the validity of the tokens before executing the corresponding action methods or commands. However, this built-in defense does not apply to page action methods and custom page controller constructors because they are executed before the anti-CSRF tokens are generated during page load.

Example 1: The following Visualforce page declares a custom contoller MyAccountActions and a page action method pageAction(). The pageAction() method is executed when visiting the page URL, and the server does not check for anti-CSRF tokens.


<apex:page controller="MyAccountActions" action="{!pageAction}">
...
</apex:page>

public class MyAccountActions {

...
public void pageAction() {
Map<String,String> reqParams = ApexPages.currentPage().getParameters();
if (params.containsKey('id')) {
Id id = reqParams.get('id');
Account acct = [SELECT Id,Name FROM Account WHERE Id = :id];
delete acct;
}
}
...
}


An attacker might set up a malicious website that contains the following code:

<img src="http://my-org.my.salesforce.com/apex/mypage?id=YellowSubmarine" height=1 width=1/>


If an administrator for the Visualforce page visits the malicious page while having an active session on the site, they will unwittingly delete accounts for the attacker.
References
[1] Salesforce Security Tips for Apex and Visualforce Development - Cross-Site Request Forgery (CSRF)
[2] A. Klein Divide and Conquer: HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics
desc.structural.apex.csrf
Abstract
State-changing HTTP requests must contain a user-specific secret to prevent an attacker from making unauthorized requests
Explanation
A Cross-Site Request Forgery (CSRF) vulnerability occurs when:
1. A Web application uses session cookies.
2. The application acts on an HTTP request without verifying that the request was made with the user's consent.

Example 1: In the following example, a Web application allows administrators to create new accounts:


RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "/new_user");
body = addToPost(body, new_username);
body = addToPost(body, new_passwd);
rb.sendRequest(body, new NewAccountCallback(callback));


An attacker might set up a malicious Web site that contains the following code:


RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://www.example.com/new_user");
body = addToPost(body, "attacker";
body = addToPost(body, "haha");
rb.sendRequest(body, new NewAccountCallback(callback));


If an administrator for example.com visits the malicious page while they have an active session on the site, they will unwittingly create an account for the attacker. This is a CSRF attack. It is possible because the application does not have a way to determine the provenance of the request. Any request could be a legitimate action chosen by the user or a faked action set up by an attacker. The attacker does not get to see the Web page that the bogus request generates, so the attack technique is only useful for requests that alter the state of the application.

Applications that pass the session identifier in the URL rather than as a cookie do not have CSRF issues because there is no way for the attacker to access the session identifier and include it as part of a bogus request.

Some frameworks automatically include CSRF nonces to help protect applications. Disabling this feature can leave the application at risk.

Example 2: This Spring Security protected application explicitly disables CSRF protection.


<http auto-config="true">
...
<csrf disabled="true"/>
</http>
References
[1] A. Klein Divide and Conquer: HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics
[2] OWASP OWASP Top 10
[3] OWASP Cross-Site Request Forgery (CSRF) Prevention Cheat Sheet
desc.config.java.csrf
Abstract
HTTP requests must contain a user-specific secret to prevent an attacker from making unauthorized requests.
Explanation
A cross-site request forgery (CSRF) vulnerability occurs when:
1. A web application uses session cookies.

2. The application acts on an HTTP request without verifying that the request was made with the user's consent.



A nonce is a cryptographic random value that is sent with a message to prevent replay attacks. If the request does not contain a nonce that proves its provenance, the code that handles the request is vulnerable to a CSRF attack (unless it does not change the state of the application). This means a web application that uses session cookies has to take special precautions to ensure that an attacker can't trick users into submitting bogus requests. Imagine a web application that allows administrators to create new accounts as follows:



var req = new XMLHttpRequest();
req.open("POST", "/new_user", true);
body = addToPost(body, new_username);
body = addToPost(body, new_passwd);
req.send(body);


An attacker might set up a malicious web site that contains the following code.


var req = new XMLHttpRequest();
req.open("POST", "http://www.example.com/new_user", true);
body = addToPost(body, "attacker");
body = addToPost(body, "haha");
req.send(body);


If an administrator for example.com visits the malicious page while she has an active session on the site, she will unwittingly create an account for the attacker. This is a CSRF attack. It is possible because the application does not have a way to determine the provenance of the request. Any request could be a legitimate action chosen by the user or a faked action set up by an attacker. The attacker does not get to see the Web page that the bogus request generates, so the attack technique is only useful for requests that alter the state of the application.

Applications that pass the session identifier in the URL rather than as a cookie do not have CSRF problems because there is no way for the attacker to access the session identifier and include it as part of the bogus request.
CSRF is entry number five on the 2007 OWASP Top 10 list.
References
[1] A. Klein Divide and Conquer: HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics
[2] OWASP 2007 OWASP Top 10
desc.structural.javascript.csrf
Abstract
The Django application does not enable the CSRF middleware protection
Explanation
A cross-site request forgery (CSRF) vulnerability occurs when:
1. A Web application uses session cookies.

2. The application acts on an HTTP request without verifying that the request was made with the user's consent.

A nonce is a cryptographic random value that is sent with a message to prevent replay attacks. If the request does not contain a nonce that proves its provenance, the code that handles the request is vulnerable to a CSRF attack (unless it does not change the state of the application). This means a Web application that uses session cookies has to take special precautions in order to ensure that an attacker can't trick users into submitting bogus requests. Imagine a Web application that allows administrators to create new accounts by submitting this form:


<form method="POST" action="/new_user" >
Name of new user: <input type="text" name="username">
Password for new user: <input type="password" name="user_passwd">
<input type="submit" name="action" value="Create User">
</form>


An attacker might set up a Web site with the following:


<form method="POST" action="http://www.example.com/new_user">
<input type="hidden" name="username" value="hacker">
<input type="hidden" name="user_passwd" value="hacked">
</form>
<script>
document.usr_form.submit();
</script>


If an administrator for example.com visits the malicious page while she has an active session on the site, she will unwittingly create an account for the attacker. This is a CSRF attack. It is possible because the application does not have a way to determine the provenance of the request. Any request could be a legitimate action chosen by the user or a faked action set up by an attacker. The attacker does not get to see the Web page that the bogus request generates, so the attack technique is only useful for requests that alter the state of the application.

Applications that pass the session identifier in the URL rather than as a cookie do not have CSRF problems because there is no way for the attacker to access the session identifier and include it as part of the bogus request.
References
[1] A. Klein Divide and Conquer: HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics
desc.structural.python.cross_site_request_forgery_django_settings
Abstract
HTTP requests must contain a user-specific secret in order to prevent an attacker from making unauthorized requests.
Explanation
A cross-site request forgery (CSRF) vulnerability occurs when:
1. A Web application uses session cookies.

2. The application acts on an HTTP request without verifying that the request was made with the user's consent.

A nonce is a cryptographic random value that is sent with a message to prevent replay attacks. If the request does not contain a nonce that proves its provenance, the code that handles the request is vulnerable to a CSRF attack (unless it does not change the state of the application). This means a Web application that uses session cookies has to take special precautions in order to ensure that an attacker can't trick users into submitting bogus requests. Imagine a Web application that allows administrators to create new accounts as follows:

By default Play Framework adds protection against CSRF, but it can be disabled globally or for certain routes.

Example: The following route definition disables the CSRF protection for the buyItem controller method.

+ nocsrf
POST /buyItem controllers.ShopController.buyItem


If a user is tricked into visiting a malicious page while she has an active session for shop.com, she will unwittingly buy items for the attacker. This is a CSRF attack. It is possible because the application does not have a way to determine the provenance of the request. Any request could be a legitimate action chosen by the user or a faked action set up by an attacker. The attacker does not get to see the Web page that the bogus request generates, so the attack technique is only useful for requests that alter the state of the application.

Applications that pass the session identifier in the URL rather than as a cookie do not have CSRF problems because there is no way for the attacker to access the session identifier and include it as part of the bogus request.
References
[1] A. Klein Divide and Conquer: HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics
[2] OWASP Cross-Site Request Forgery (CSRF) Prevention Cheat Sheet
desc.semantic.scala.cross_site_request_forgery
Abstract
Form posts must contain a user-specific secret in order to prevent an attacker from making unauthorized requests.
Explanation
A cross-site request forgery (CSRF) vulnerability occurs when:
1. A Web application uses session cookies.

2. The application acts on an HTTP request without verifying that the request was made with the user's consent.



A nonce is a cryptographic random value that is sent with a message to prevent replay attacks. If the request does not contain a nonce that proves its provenance, the code that handles the request is vulnerable to a CSRF attack (unless it does not change the state of the application). This means a Web application that uses session cookies has to take special precautions in order to ensure that an attacker can't trick users into submitting bogus requests. Imagine a Web application that allows administrators to create new accounts by submitting this form:


<form method="POST" action="/new_user" >
Name of new user: <input type="text" name="username">
Password for new user: <input type="password" name="user_passwd">
<input type="submit" name="action" value="Create User">
</form>


An attacker might set up a Web site with the following:


<form method="POST" action="http://www.example.com/new_user">
<input type="hidden" name="username" value="hacker">
<input type="hidden" name="user_passwd" value="hacked">
</form>
<script>
document.usr_form.submit();
</script>


If an administrator for example.com visits the malicious page while she has an active session on the site, she will unwittingly create an account for the attacker. This is a CSRF attack. It is possible because the application does not have a way to determine the provenance of the request. Any request could be a legitimate action chosen by the user or a faked action set up by an attacker. The attacker does not get to see the Web page that the bogus request generates, so the attack technique is only useful for requests that alter the state of the application.

Applications that pass the session identifier in the URL rather than as a cookie do not have CSRF problems because there is no way for the attacker to access the session identifier and include it as part of the bogus request.

CSRF is entry number five on the 2007 OWASP Top 10 list.
References
[1] A. Klein Divide and Conquer: HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics
[2] OWASP 2007 OWASP Top 10
desc.content.html.csrf
Abstract
Disabling the X-Download-Options header being set to noopen, allows downloaded HTML pages to run in the security context of the site serving them.
Explanation
When sites need to be able to serve downloads to users, the option to open them means that any served files that run in the browser could be opened in the current browser in the same security context as the site.
If an attacker is able to manipulate the downloaded files, they can insert HTML or scripts that run in the browser to act as a cross-site scripting attack, stealing or manipulating information in the current session.

Example 1: The following example explicitly disables protections against served downloads running in the browser:


var express = require('express');
var app = express();
var helmet = require('helmet');

app.use(helmet({
ieNoOpen: false
}));
...
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 5
[2] Standards Mapping - CIS Microsoft Azure Foundations Benchmark complete
[3] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[4] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[5] Standards Mapping - CIS Google Kubernetes Engine Benchmark integrity
[6] Standards Mapping - CIS Kubernetes Benchmark complete
[7] Standards Mapping - Common Weakness Enumeration CWE ID 79, CWE ID 80
[8] Standards Mapping - Common Weakness Enumeration Top 25 2019 [2] CWE ID 079
[9] Standards Mapping - Common Weakness Enumeration Top 25 2020 [1] CWE ID 079
[10] Standards Mapping - Common Weakness Enumeration Top 25 2021 [2] CWE ID 079
[11] Standards Mapping - Common Weakness Enumeration Top 25 2022 [2] CWE ID 079
[12] Standards Mapping - Common Weakness Enumeration Top 25 2023 [2] CWE ID 079
[13] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001310, CCI-002754
[14] Standards Mapping - FIPS200 SI
[15] Standards Mapping - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[16] Standards Mapping - NIST Special Publication 800-53 Revision 4 SI-10 Information Input Validation (P1)
[17] Standards Mapping - NIST Special Publication 800-53 Revision 5 SI-10 Information Input Validation
[18] Standards Mapping - OWASP Top 10 2004 A4 Cross Site Scripting
[19] Standards Mapping - OWASP Top 10 2007 A1 Cross Site Scripting (XSS)
[20] Standards Mapping - OWASP Top 10 2010 A2 Cross-Site Scripting (XSS)
[21] Standards Mapping - OWASP Top 10 2013 A3 Cross-Site Scripting (XSS)
[22] Standards Mapping - OWASP Top 10 2017 A7 Cross-Site Scripting (XSS)
[23] Standards Mapping - OWASP Top 10 2021 A03 Injection
[24] Standards Mapping - OWASP Application Security Verification Standard 4.0 5.3.3 Output Encoding and Injection Prevention Requirements (L1 L2 L3), 5.3.6 Output Encoding and Injection Prevention Requirements (L1 L2 L3)
[25] Standards Mapping - OWASP Mobile 2014 M7 Client Side Injection
[26] Standards Mapping - OWASP Mobile 2024 M4 Insufficient Input/Output Validation
[27] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.4
[28] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 Requirement 6.3.1.1, Requirement 6.5.1
[29] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 Requirement 6.5.7
[30] Standards Mapping - Payment Card Industry Data Security Standard Version 3.0 Requirement 6.5.7
[31] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2 Requirement 6.5.7
[32] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2.1 Requirement 6.5.7
[33] Standards Mapping - Payment Card Industry Data Security Standard Version 3.1 Requirement 6.5.7
[34] Standards Mapping - Payment Card Industry Data Security Standard Version 4.0 Requirement 6.2.4
[35] Standards Mapping - Payment Card Industry Software Security Framework 1.0 Control Objective 4.2 - Critical Asset Protection
[36] Standards Mapping - Payment Card Industry Software Security Framework 1.1 Control Objective 4.2 - Critical Asset Protection
[37] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective 4.2 - Critical Asset Protection
[38] Standards Mapping - SANS Top 25 2009 Insecure Interaction - CWE ID 079
[39] Standards Mapping - SANS Top 25 2010 Insecure Interaction - CWE ID 079
[40] Standards Mapping - SANS Top 25 2011 Insecure Interaction - CWE ID 079
[41] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP3510 CAT I, APP3580 CAT I
[42] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP3510 CAT I, APP3580 CAT I
[43] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP3510 CAT I, APP3580 CAT I
[44] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP3510 CAT I, APP3580 CAT I
[45] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP3510 CAT I, APP3580 CAT I
[46] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP3510 CAT I, APP3580 CAT I
[47] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP3510 CAT I, APP3580 CAT I
[48] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[49] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[50] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[51] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[52] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[53] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[54] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[55] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[56] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[57] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[58] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[59] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[60] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[61] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002490 CAT I, APSC-DV-002560 CAT I
[62] Standards Mapping - Web Application Security Consortium Version 2.00 Cross-Site Scripting (WASC-08)
[63] Standards Mapping - Web Application Security Consortium 24 + 2 Cross-Site Scripting
desc.dataflow.javascript.cross_site_scripting_untrusted_html_downloads
Abstract
Server fails to verify request origin effectively accepting cross-domain requests which can be used by an attacker to hijack a bidirectional WebSocket connection.
Explanation
Cross-Site WebSocket Hijacking occurs when a user is tricked into visiting a malicious site that will establish a WebSocket connection with a legitimate backend server. The initial HTTP request used to ask the server for upgrading to WebSocket protocol is a regular HTTP request and so, the browser will send any cookies bound to the target domain including any session cookies. If the server fails to verify the Origin header, it will allow any malicious site to impersonate the user and establish a bidirectional WebSocket connection without the user even noticing.
References
[1] Christian Schneider Cross-Site WebSocket Hijacking
desc.semantic.dotnet.cross_site_websocket_hijacking
Abstract
The server fails to verify requests' origins, thereby accepting cross-domain requests which may be used by an attacker to hijack bidirectional WebSocket connections.
Explanation
Cross-Site WebSocket Hijacking occurs when a user is tricked into visiting a malicious site that will establish a WebSocket connection with a legitimate backend server. The initial HTTP request used to ask the server for upgrading to WebSocket protocol is a regular HTTP request and so, the browser will send any cookies bound to the target domain including any session cookies. If the server fails to verify the Origin header, it will allow any malicious site to impersonate the user and establish a bidirectional WebSocket connection without the user even noticing.
References
[1] Christian Schneider Cross-Site WebSocket Hijacking
desc.semantic.java.cross_site_websocket_hijacking
Abstract
The application uses a deny list to control which attributes are exposed by a form. Developers can forget to update the deny list when adding new attributes and may accidentally expose sensitive fields to attackers.
Explanation
The application uses an exclude deny list. This is hard to maintain and error prone. If developers add new fields to the form or Model that backs up the form and forget to update the exclude filter, they may be exposing sensitive fields to attackers. Attackers will be able to submit and bind malicious data to any non-excluded field.

Example 1: The following form exposes some User attributes but checks a deny list for the user id:


from myapp.models import User
...
class UserForm(ModelForm):
class Meta:
model = User
exclude = ['id']
...


If User model was updated with a new role attribute and the associated UserForm was not updated, the role attribute would be exposed in the form.
References
[1] Django Foundation Creating forms from models
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 3
[3] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[4] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 2
[5] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[6] Standards Mapping - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[7] Standards Mapping - OWASP API 2023 API3 Broken Object Property Level Authorization
[8] Standards Mapping - OWASP Mobile 2024 M8 Security Misconfiguration
desc.structural.python.django_bad_practices_attributes_in_deny_list
Abstract
Transmitting sensitive information via GET parameters can expose the application to Cross-Site Request Forgery attacks.
Explanation
Some web frameworks collapse the POST and GET parameters into a single collection. This is a flawed design pattern from a security standpoint. If a page accepts POST parameters as GET parameters an attacker would be able to affect change on websites through Cross-Site Request Forgery or leverage this design flaw with other vulnerabilities to attack the system hosting the web application.
desc.dynamic.xtended_preview.exposure_of_post_parameters_in_get_request
Abstract
Loading a file that can run unstrusted scripts within the context of your application is dangerous.
Explanation
File Based Cross Zone Scripting occurs when the following conditions are met:

1. A file is loaded that could allow scripts to be run within your application

2. The script loaded is taken to be of same origin as the running application.

When both these conditions are met a series of attacks can be enabled, especially if other parties determine trust based on whether the information is coming from within the boundaries of your application.

Example 1: The following code uses an Android WebView in order to load a file locally:

...
myWebView.loadUrl("file:///android_asset/www/index.html");
...

In Example 1, the Android WebView renderer treats everything loaded with loadUrl() with a URL starting with "file://" as being in the same origin.

There are a few typical ways for an attacker to leverage a File Based Cross-Zone Scripting vulnerability when loading from a file:
- the local file could be manipulated by an attacker, who could inject script into the file.
This will be dependent on file permissions, where the file is located, or race conditions where a file may be saved and then loaded (there could be a time window for modification).

- the file may call out to an external resource.
This may occur when the file loaded retrieves scripts from an external resource.

Example 2: The following code looks at an external source to determine the JavaScript that it should run.

<script src="http://www.example.com/js/fancyWidget.js"></script>

In Example 2, an insecure protocol is being used that could permit the resulting script to be modified by a malicious actor. Alternatively, other attacks could be performed to re-route the machine to an attacker's site.

- the file loaded may contain cross-site scripting vulnerabilities.
If the file being loaded is able to have code injected, the injected code may be able to then run in the context of your application. This may not necessarily be the ability to inject JavaScript, but simply being able to inject HTML may also enable defacements or Denial of Service attacks.
References
[1] Erika Chin and David Wagner Bifocals: Analyzing WebView Vulnerabilities in Android Applications
desc.semantic.java.file_based_cross_zone_scripting
Abstract
Loading local file that can run untrusted scripts within the privileged context of your application is dangerous.
Explanation
File-based cross-zone scripting occurs when the following conditions are met:

1. A file is loaded that could allow scripts to be run within your application.


2. The script loaded is viewed as having the same origin as the running application (file://).

When both of these conditions are met a series of attacks may be enabled, especially if other parties determine trust based on whether the information is coming from within the boundaries of your application.

Example 1: The following code uses the UIWebView.loadRequest(_:) method to load a local file:

...
NSURL *url = [[NSBundle mainBundle] URLForResource: filename withExtension:extension];
[webView loadRequest:[[NSURLRequest alloc] initWithURL:url]];
...


In Example 1, the WebView engine treats everything loaded with UIWebView.loadRequest(_:) with a URL starting with file:// as being in the privileged local file origin.

There are a few typical ways for an attacker to leverage a file-based cross-zone scripting vulnerability when loading from a file:

- The local file may be controlled by the attacker. For example, the attacker may send the file to its victim which then proceeds to store it on the vulnerable application (for example: a cloud storage application)
- The local file could be manipulated by an attacker, who could inject script into the file. This will be dependent on file permissions, where the file is located, or race conditions where a file may be saved and then loaded (there could be a time window for modification).
- The file may call out to an external resource. This may occur when the loaded file retrieves scripts from an external resource.
- The loaded file may contain cross-site scripting vulnerabilities. If the file being loaded contains injected code, this code may then be run in the context of your application. The injected code does not need to be JavaScript code - injected HTML may also enable defacements or denial of service attacks.

If the attacker-controlled file is loaded locally with a file:// URL, the Same Origin Policy will allow the scripts in this file to access any other file from the same origin, which may let an attacker access any local files containing sensitive information.
References
[1] Same-origin policy for file: URIs Mozilla
[2] Old Habits Die Hard: Cross-Zone Scripting in Dropbox & Google Drive Mobile Apps IBM
[3] loadHTMLString(_:baseURL:) API documentation Apple
[4] loadRequest(_:) API documentation Apple
desc.dataflow.objc.file_based_cross_zone_scripting
Abstract
Loading local file that can run untrusted scripts within the privileged context of your application is dangerous.
Explanation
File-based cross-zone scripting occurs when the following conditions are met:

1. A file is loaded that could allow scripts to be run within your application.


2. The script loaded is viewed as having the same origin as the running application (file://).

When both of these conditions are met a series of attacks may be enabled, especially if other parties determine trust based on whether the information is coming from within the boundaries of your application.

Example 1: The following code uses the UIWebView.loadRequest(_:) method to load a local file:

...
let url = Bundle.main.url(forResource: filename, withExtension: extension)
self.webView!.load(URLRequest(url:url!))
...


In Example 1, the WebView engine treats everything loaded with UIWebView.loadRequest(_:) with a URL starting with file:// as being in the privileged local file origin.

There are a few typical ways for an attacker to leverage a file-based cross-zone scripting vulnerability when loading from a file:

- The local file may be controlled by the attacker. For example, the attacker may send the file to its victim which then proceeds to store it on the vulnerable application (for example: a cloud storage application)
- The local file could be manipulated by an attacker, who could inject script into the file. This will be dependent on file permissions, where the file is located, or race conditions where a file may be saved and then loaded (there could be a time window for modification).
- The file may call out to an external resource. This may occur when the loaded file retrieves scripts from an external resource.
- The loaded file may contain cross-site scripting vulnerabilities. If the file being loaded contains injected code, this code may then be run in the context of your application. The injected code does not need to be JavaScript code - injected HTML may also enable defacements or denial of service attacks.

If the attacker-controlled file is loaded locally with a file:// URL, the Same Origin Policy will allow the scripts in this file to access any other file from the same origin, which may let an attacker access any local files containing sensitive information.
References
[1] Same-origin policy for file: URIs Mozilla
[2] Old Habits Die Hard: Cross-Zone Scripting in Dropbox & Google Drive Mobile Apps IBM
[3] loadHTMLString(_:baseURL:) API documentation Apple
[4] loadRequest(_:) API documentation Apple
desc.dataflow.swift.file_based_cross_zone_scripting