Data Validation & Encoding (VE5)
Jee puede eludir las rutinas de codificación centralizadas, ya que dichas rutinas no son usadas por todos los activos o se están utilizando codificaciones incorrectas
This card relates to bypass of output encoding. See Data Validation & Encoding 6 for the similar bypass of input data validation.
Scenario: Jee’s Encoding Bypass
Picture a scenario where Jee, a clever adversary, bypasses your system's security by exploiting inconsistencies in encoding routines. This happens because:
- Inconsistent Use of Encoding Routines: Centralized encoding routines are not uniformly applied across the system.
- Incorrect Encoding Choices: The system uses wrong or inappropriate encoding methods for certain types of data.
Example
Jee finds that while your website correctly encodes data for HTML context, it fails to do so for JavaScript contexts. She inputs a string that is harmless in HTML but malicious in JavaScript, like a script tag with a JavaScript command. Since the system only encodes for HTML, it fails to neutralize the threat in the JavaScript context, leading to a Cross-Site Scripting (XSS) vulnerability.
Threat Modeling
STRIDE
This scenario is clearly STRIDE: Information Disclosure and Tampering. Bypassing or mis-using output encoding lets attacker-controlled data be sent to and executed in another party’s context. This lets the attacker can alter the rendered page or responses (injecting or changing content seen by users) which is Tampering, but the most immediate consequence is exposure and theft of sensitive information (session cookies, DOM data, or secrets accessible in-page) — which maps best to Information Disclosure.
What can go wrong?
These gaps in encoding practices can lead to serious security vulnerabilities compromising both the system and its users. Some common attacks of bad implementation (or lack) of output encoding routines are:
- Cross Site Scripting (XSS)
- Code injection
- Fuzzing
For more things that can go wrong, see the Common Attack Patterns related to this card in the table below.
What are we going to do about it?
Centralized output encoding routines are a good programming practice, but developers need to understand how they work, how to use them and any limitations. Such routines can be tested independently of other code and not only provide assurance on the quality of the validation, but it makes refactorization an easy task and it eliminates code duplicates and bad interpretations. Ouput encodings are a must when handling data from un-trusted sources. It should also be a mandatory security check when outputting data to queries for SQL, XML, and LDAP and in every case when hazardous special characters must be allowed as input (such as < > " ' % ( ) & + \ ). If third-party sanitization libraries are used, it is important to test each routine before its implementation.
- Ensure consistent application of centralized encoding routines across all parts of the system.
- Use the correct encoding methods appropriate for each specific data context.
- Regularly review and update encoding practices to cover all potential data handling scenarios.
For detailed advice on how to mitigate threats related to the card, see the ASVS and OWASP Developer Guide requirements in the table below.
Mappings
STRIDE: Tampering,Information Disclosure
OWASP ASVS: 1.1.6,5.3.3,5.2.1,5.2.2,5.2.5
CAPEC: 28,43,64,72,120,152,267
OWASP DevGuide: SQ3,SQ4,CEC3,CEC4,CEC5,CEC6,COE1,COE2
OWASP AppSensor: -