What it is: Improper Handling of Alternate Encoding (CWE-173) is a type of security misconfiguration vulnerability that occurs when a product doesn't properly handle an input using an alternate encoding that is valid for the control sphere to which the input is being sent.
Why it matters: Improper Handling of Alternate Encoding can lead to bypassing protection mechanisms and compromising confidentiality, integrity, or availability. It's essential to implement proper handling of alternate encodings to prevent this vulnerability.
How to fix it: To fix Improper Handling of Alternate Encoding, you should implement input validation, output encoding, and avoid making decisions based on names of resources that can have alternate names.
TL;DR: Improper Handling of Alternate Encoding (CWE-173) is a security misconfiguration vulnerability that occurs when a product doesn’t properly handle an input using an alternate encoding. To fix it, implement input validation, output encoding, and avoid making decisions based on names of resources that can have alternate names.
At-a-Glance
| Field | Value |
|---|---|
| CWE ID | CWE-173 |
| OWASP Category | A9:2021 - Security Misconfiguration |
| CAPEC | CAPEC-120, CAPEC-267, CAPEC-3, CAPEC-4, CAPEC-52, CAPEC-53, CAPEC-64, CAPEC-71, CAPEC-72, CAPEC-78, CAPEC-79, CAPEC-80 |
| Typical Severity | Critical |
| Affected Technologies | Web applications, web services |
| Detection Difficulty | Moderate |
| Last Updated | 2026-07-28 |
What is Improper Handling of Alternate Encoding?
Improper Handling of Alternate Encoding (CWE-173) is a type of security misconfiguration vulnerability that occurs when a product doesn’t properly handle an input using an alternate encoding that is valid for the control sphere to which the input is being sent. As defined by the MITRE Corporation under CWE-173, and classified by the OWASP Foundation under A9:2021 - Security Misconfiguration…
Quick Summary
Improper Handling of Alternate Encoding (CWE-173) can lead to bypassing protection mechanisms and compromising confidentiality, integrity, or availability. It’s essential to implement proper handling of alternate encodings to prevent this vulnerability.
Jump to: Quick Summary · Improper Handling of Alternate Encoding Overview · How Improper Handling of Alternate Encoding Works · Business Impact of Improper Handling of Alternate Encoding · Improper Handling of Alternate Encoding Attack Scenario · How to Detect Improper Handling of Alternate Encoding · How to Fix Improper Handling of Alternate Encoding · Framework-Specific Fixes for Improper Handling of Alternate Encoding · How to Ask AI to Check Your Code for Improper Handling of Alternate Encoding · Improper Handling of Alternate Encoding Best Practices Checklist · Improper Handling of Alternate Encoding FAQ · Vulnerabilities Related to Improper Handling of Alternate Encoding · References · Scan Your Own Site
Improper Handling of Alternate Encoding Overview
What: Improper Handling of Alternate Encoding (CWE-173) is a type of security misconfiguration vulnerability that occurs when a product doesn’t properly handle an input using an alternate encoding.
Why it matters: Improper Handling of Alternate Encoding can lead to bypassing protection mechanisms and compromising confidentiality, integrity, or availability.
Where it occurs: This vulnerability can occur in web applications and web services.
Who is affected: Any product that doesn’t properly handle inputs using alternate encodings can be affected by this vulnerability.
Who is NOT affected: Applications that never construct paths/queries/commands from external input are not affected by this vulnerability.
How Improper Handling of Alternate Encoding Works
Root Cause
The root cause of Improper Handling of Alternate Encoding (CWE-173) is the failure to properly handle inputs using alternate encodings.
Attack Flow
- An attacker sends an input using an alternate encoding that is valid for the control sphere.
- The product does not properly handle the input, allowing the attacker to bypass protection mechanisms and compromise confidentiality, integrity, or availability.
Prerequisites to Exploit
- The product must be vulnerable to Improper Handling of Alternate Encoding (CWE-173).
- The attacker must have access to an alternate encoding that is valid for the control sphere.
- The product must not properly handle inputs using alternate encodings.
Vulnerable Code
import os
path = request.form['path']
os.chdir(path)
This code does not properly handle an input using an alternate encoding that is valid for the control sphere to which the input is being sent.
Secure Code
import os
path = request.form['path']
if not os.path.abspath(path).startswith(base_dir):
raise ValueError('Invalid path')
os.chdir(path)
This code properly handles an input using an alternate encoding that is valid for the control sphere to which the input is being sent.
Business Impact of Improper Handling of Alternate Encoding
Confidentiality: Improper Handling of Alternate Encoding (CWE-173) can lead to bypassing protection mechanisms and compromising confidentiality.
- Exposed sensitive data
- Unauthorized access to confidential information
Integrity: Improper Handling of Alternate Encoding (CWE-173) can lead to bypassing protection mechanisms and compromising integrity.
- Data tampering or modification
- Unauthorized changes to system settings
Availability: Improper Handling of Alternate Encoding (CWE-173) can lead to bypassing protection mechanisms and compromising availability.
- System downtime or crashes
- Denial-of-service attacks
Improper Handling of Alternate Encoding Attack Scenario
- An attacker sends an input using an alternate encoding that is valid for the control sphere.
- The product does not properly handle the input, allowing the attacker to bypass protection mechanisms and compromise confidentiality, integrity, or availability.
How to Detect Improper Handling of Alternate Encoding
Manual Testing
- Send inputs using alternate encodings that are valid for the control sphere.
- Verify if the product properly handles the inputs.
- Check for any signs of bypassing protection mechanisms and compromising confidentiality, integrity, or availability.
Automated Scanners (SAST / DAST)
- Static analysis can catch some instances of Improper Handling of Alternate Encoding (CWE-173), but dynamic analysis is required to detect all instances.
- PenScan’s scanner engines actively test for this issue.
PenScan Detection
PenScan’s scanner engines actively test for Improper Handling of Alternate Encoding (CWE-173).
False Positive Guidance
- Be cautious when interpreting results from automated scanners, as some false positives may occur.
- Verify the findings manually to ensure accuracy.
How to Fix Improper Handling of Alternate Encoding
- Implement input validation and output encoding.
- Avoid making decisions based on names of resources that can have alternate names.
Framework-Specific Fixes for Improper Handling of Alternate Encoding
Python/Django
import os
path = request.form['path']
if not os.path.abspath(path).startswith(base_dir):
raise ValueError('Invalid path')
os.chdir(path)
This code properly handles an input using an alternate encoding that is valid for the control sphere to which the input is being sent.
Java/Node.js
import java.io.File;
String path = request.getParameter("path");
if (!new File(path).getAbsolutePath().startsWith(base_dir)) {
throw new RuntimeException("Invalid path");
}
This code properly handles an input using an alternate encoding that is valid for the control sphere to which the input is being sent.
How to Ask AI to Check Your Code for Improper Handling of Alternate Encoding
Review the following Python/Django code block for potential CWE-173 Improper Handling of Alternate Encoding vulnerabilities and rewrite it using input validation and output encoding:
import os
path = request.form['path']
os.chdir(path)
Rewrite it as follows:
import os
path = request.form['path']
if not os.path.abspath(path).startswith(base_dir):
raise ValueError('Invalid path')
os.chdir(path)
Improper Handling of Alternate Encoding Best Practices Checklist
✅ Implement input validation and output encoding.
✅ Avoid making decisions based on names of resources that can have alternate names.
Improper Handling of Alternate Encoding FAQ
How does Improper Handling of Alternate Encoding occur?
Improper Handling of Alternate Encoding occurs when a product doesn’t properly handle an input using an alternate encoding that is valid for the control sphere to which the input is being sent.
What are the consequences of Improper Handling of Alternate Encoding?
The consequences of Improper Handling of Alternate Encoding can include bypassing protection mechanisms and compromising confidentiality, integrity, or availability.
How do I detect Improper Handling of Alternate Encoding in my application?
You can detect Improper Handling of Alternate Encoding using manual testing and automated scanners, such as PenScan’s scanner engines.
What are the best practices for preventing Improper Handling of Alternate Encoding?
The best practices for preventing Improper Handling of Alternate Encoding include input validation, output encoding, and avoiding making decisions based on names of resources that can have alternate names.
Can you provide an example of vulnerable code for Improper Handling of Alternate Encoding?
Yes, the following is an example of vulnerable code for Improper Handling of Alternate Encoding: This code does not properly handle an input using an alternate encoding that is valid for the control sphere to which the input is being sent.
How do I fix Improper Handling of Alternate Encoding in my application?
You can fix Improper Handling of Alternate Encoding by implementing input validation, output encoding, and avoiding making decisions based on names of resources that can have alternate names.
What are the related CWEs to Improper Handling of Alternate Encoding?
The related CWEs to Improper Handling of Alternate Encoding include CWE-172 (Encoding Error) and CWE-289 (Authentication Bypass by Alternate Name).
Can you provide an example of secure code for Improper Handling of Alternate Encoding?
Yes, the following is an example of secure code for Improper Handling of Alternate Encoding: This code properly handles an input using an alternate encoding that is valid for the control sphere to which the input is being sent.
Vulnerabilities Related to Improper Handling of Alternate Encoding
| CWE | Name | Relationship |
|---|---|---|
| CWE-172 | Encoding Error | ChildOf |
| CWE-289 | Authentication Bypass by Alternate Name | CanPrecede |
References
Scan Your Own Site
Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Improper Handling of Alternate Encoding and other risks before an attacker does.