This weakness can be detected using tools and techniques that require manual (human) analysis, such as penetration testing, threat modeling, and interactive tools that allow the tester to record and modify an active session. Specifically, manual analysis can be useful for finding this weakness, and for minimizing false positives assuming an understanding of business logic. However, it might not achieve desired code coverage within limited time constraints. For black-box analysis, if credentials are not known for privileged accounts, then the most security-critical portions of the application may not receive sufficient attention. Consider using OWASP CSRFTester to identify potential issues and aid in manual analysis.
Cross-Site Request Forgery (CSRF)
Cross-Site Request Forgery (CSRF) happens when a web application cannot reliably tell if a user actually intended to submit a request, allowing an attacker to trick a user's browser into performing…
What is CWE-352?
Real-world CVEs caused by CWE-352
-
Add user accounts via a URL in an img tag
-
Add user accounts via a URL in an img tag
-
Arbitrary code execution by specifying the code in a crafted img tag or URL
-
Gain administrative privileges via a URL in an img tag
-
Delete a victim's information via a URL or an img tag
-
Change another user's settings via a URL or an img tag
-
Perform actions as administrator via a URL or an img tag
-
modify password for the administrator
Angreiferpfad Schritt für Schritt
- 1
This example PHP code attempts to secure the form submission process by validating that the user submitting the form has a valid session. A CSRF attack would not be prevented by this countermeasure because the attacker forges a request through the user's web browser in which a valid session already exists.
- 2
The following HTML is intended to allow a user to update a profile.
- 3
profile.php contains the following code.
- 4
This code may look protected since it checks for a valid session. However, CSRF attacks can be staged from virtually any tag or HTML construct, including image tags, links, embed or object tags, or other attributes that load background images.
- 5
The attacker can then host code that will silently change the username and email address of any user that visits the page while remaining logged in to the target web application. The code might be an innocent-looking web page such as:
Vulnerable HTML
The following HTML is intended to allow a user to update a profile.
<form action="/url/profile.php" method="post">
<input type="text" name="firstname"/>
<input type="text" name="lastname"/>
<br/>
<input type="text" name="email"/>
<input type="submit" name="submit" value="Update"/>
</form> The attacker can then host code that will silently change the username and email address of any user that visits the page while remaining logged in to the target web application. The code might be an innocent-looking web page such as:
<SCRIPT>
function SendAttack () {
form.email = "attacker@example.com";
```
// send to profile.php*
form.submit();}
</SCRIPT>
<BODY onload="javascript:SendAttack();">
<form action="http://victim.example.com/profile.php" id="form" method="post">
<input type="hidden" name="firstname" value="Funny">
<input type="hidden" name="lastname" value="Joke">
<br/>
<input type="hidden" name="email">
</form> Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
const safe = validateAndEscape(input);
return executeWithGuards(safe);
} How to prevent CWE-352
- Architecture and Design Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid [REF-1482]. For example, use anti-CSRF packages such as the OWASP CSRFGuard. [REF-330] Another example is the ESAPI Session Management control, which includes a component for CSRF. [REF-45]
- Implementation Ensure that the application is free of cross-site scripting issues (CWE-79), because most CSRF defenses can be bypassed using attacker-controlled script.
- Architecture and Design Generate a unique nonce for each form, place the nonce into the form, and verify the nonce upon receipt of the form. Be sure that the nonce is not predictable (CWE-330). [REF-332]
- Architecture and Design Identify especially dangerous operations. When the user performs a dangerous operation, send a separate confirmation request to ensure that the user intended to perform that operation.
- Architecture and Design Use the "double-submitted cookie" method as described by Felten and Zeller: When a user visits a site, the site should generate a pseudorandom value and set it as a cookie on the user's machine. The site should require every form submission to include this value as a form value and also as a cookie value. When a POST request is sent to the site, the request should only be considered valid if the form value and the cookie value are the same. Because of the same-origin policy, an attacker cannot read or modify the value stored in the cookie. To successfully submit a form on behalf of the user, the attacker would have to correctly guess the pseudorandom value. If the pseudorandom value is cryptographically strong, this will be prohibitively difficult. This technique requires Javascript, so it may not work for browsers that have Javascript disabled. [REF-331]
- Architecture and Design Do not use the GET method for any request that triggers a state change.
- Implementation Check the HTTP Referer header to see if the request originated from an expected page. This could break legitimate functionality, because users or proxies may have disabled sending the Referer for privacy reasons.
How to detect CWE-352
CSRF is currently difficult to detect reliably using automated techniques. This is because each application has its own implicit security policy that dictates which requests can be influenced by an outsider and automatically performed on behalf of a user, versus which requests require strong confidence that the user intends to make the request. For example, a keyword search of the public portion of a web site is typically expected to be encoded within a link that can be launched automatically when the user clicks on the link.
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Bytecode Weakness Analysis - including disassembler + source code weakness analysis Binary Weakness Analysis - including disassembler + source code weakness analysis
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Binary / Bytecode disassembler - then use manual analysis for vulnerabilities & anomalies
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Web Application Scanner
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Fuzz Tester Framework-based Fuzzer
Plexicus erkennt CWE-352 automatisch und öffnet in unter 60 Sekunden einen Fix-PR.
Codex Remedium scannt jeden Commit, identifiziert genau diese Schwachstelle und liefert einen reviewer-ready Pull Request mit dem Patch. Keine Tickets. Keine Hand-offs.
Frequently asked questions
Was ist CWE-352?
Cross-Site Request Forgery (CSRF) happens when a web application cannot reliably tell if a user actually intended to submit a request, allowing an attacker to trick a user's browser into performing unwanted actions on their behalf.
Wie gravierend ist CWE-352?
MITRE stuft die Exploit-Wahrscheinlichkeit als mittel ein — eine Ausnutzung ist realistisch, erfordert aber meist bestimmte Bedingungen.
Welche Sprachen oder Plattformen sind von CWE-352 betroffen?
MITRE lists the following affected platforms: Web Server.
Wie kann ich CWE-352 verhindern?
Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid [REF-1482]. For example, use anti-CSRF packages such as the OWASP CSRFGuard. [REF-330] Another example is the ESAPI Session Management control, which includes a component for CSRF. [REF-45] Ensure that the application is free of cross-site scripting issues (CWE-79), because most CSRF defenses can be bypassed using attacker-controlled script.
Wie erkennt und behebt Plexicus CWE-352?
Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-352 bei jedem Commit. Bei einem Treffer öffnet unser Codex-Remedium-Agent einen Fix-PR mit korrigiertem Code, Tests und einer einzeiligen Zusammenfassung für den Reviewer.
Wo erfahre ich mehr über CWE-352?
MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/352.html. Für ergänzende Hinweise kannst du auch die OWASP- und NIST-Dokumentation heranziehen.
Weaknesses related to CWE-352
Insufficient Verification of Data Authenticity
This vulnerability occurs when an application fails to properly check where data comes from or confirm its legitimacy, allowing untrusted…
Missing Source Correlation of Multiple Independent Data
This vulnerability occurs when a system trusts a single source of data without verification, making it impossible to detect if that source…
Origin Validation Error
This vulnerability occurs when an application fails to properly confirm the true origin of incoming data or communication, allowing…
Improper Verification of Cryptographic Signature
This vulnerability occurs when an application fails to properly check the digital signature on data, or skips the verification step…
Use of Less Trusted Source
This vulnerability occurs when a system has access to multiple sources for the same critical data, but it chooses to rely on the less…
Acceptance of Extraneous Untrusted Data With Trusted Data
This vulnerability occurs when a system processes both trusted and untrusted data together, but fails to separate them. The application…
Insufficient Type Distinction
This vulnerability occurs when an application fails to properly differentiate between different types of data or objects, leading to…
Missing Support for Integrity Check
This vulnerability occurs when a system uses a communication protocol that lacks built-in integrity verification, such as a checksum or…
Improper Validation of Integrity Check Value
This vulnerability occurs when software fails to properly check the integrity of data by validating its checksum or hash value. Without…
Further reading
- MITRE — offizielle CWE-352 https://cwe.mitre.org/data/definitions/352.html
- Cross-Site Request Forgeries (Re: The Dangers of Allowing Users to Post Images) https://marc.info/?l=bugtraq&m=99263135911884&w=2
- Cross-Site Request Forgery (CSRF) Prevention Cheat Sheet https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html
- Cross-Site Request Forgeries: Exploitation and Prevention https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.147.1445
- CSRF - The Cross-Site Request Forgery (CSRF/XSRF) FAQ https://www.cgisecurity.com/csrf-faq.html
- Cross-site request forgery https://en.wikipedia.org/wiki/Cross-site_request_forgery
Schluss mit dem Bezahlen pro Entwickler.
Schließ den Kreislauf.
Plexicus ist die KI-native ASPM, die scannt, filtert, fixt, pentestet und erklärt — autonom. Unbegrenzte Entwickler, unbegrenzte Repos, Fair-Use-KI-Aktionen. Echter kostenloser Tarif, €269/mo jährlich, wenn du bereit bist.