1348
Phase: Architecture and Design
Strategy = Enforcement by Conversion
When the set of acceptable objects, such as filenames or URLs, is limited or known, create a
mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs,
and reject all other inputs. For example, ID 1 could map to "/login.asp" and ID 2 could map to
"http://www.example.com/". Features such as the ESAPI AccessReferenceMap [REF-45] provide
this capability.
Phase: Architecture and Design
Ensure that no externally-supplied requests are honored by requiring that all redirect requests
include a unique nonce generated by the application [REF-483]. Be sure that the nonce is not
predictable (CWE-330).
Phase: Architecture and Design
Phase: Implementation
Strategy = Attack Surface Reduction
Understand all the potential areas where untrusted inputs can enter your software: parameters
or arguments, cookies, anything read from the network, environment variables, reverse DNS
lookups, query results, request headers, URL components, e-mail, files, filenames, databases,
and any external systems that provide data to the application. Remember that such inputs
may be obtained indirectly through API calls. Many open redirect problems occur because the
programmer assumed that certain inputs could not be modified, such as cookies and hidden form
fields.
Phase: Operation
Strategy = Firewall
Use an application firewall that can detect attacks against this weakness. It can be beneficial
in cases in which the code cannot be fixed (because it is controlled by a third party), as an
emergency prevention measure while more comprehensive software assurance measures are
applied, or to provide defense in depth.
Effectiveness = Moderate
An application firewall might not cover all possible input vectors. In addition, attack techniques
might be available to bypass the protection mechanism, such as using malformed inputs that can
still be processed by the component that receives those inputs. Depending on functionality, an
application firewall might inadvertently reject or modify legitimate requests. Finally, some manual
effort may be required for customization.
Demonstrative Examples
Example 1:
The following code obtains a URL from the query string and then redirects the user to that URL.
Example Language: PHP (Bad)
$redirect_url = $_GET['url'];
header("Location: " . $redirect_url);
The problem with the above code is that an attacker could use this page as part of a phishing
scam by redirecting users to a malicious site. For example, assume the above code is in the file
example.php. An attacker could supply a user with the following link:
Example Language: (Attack)
http://example.com/example.php?url=http://malicious.example.com
CWE Version 4.14
CWE-601: URL Redirection to Untrusted Site ('Open Redirect')
CWE-601: URL Redirection to Untrusted Site ('Open Redirect')