-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3363 from semgrep/merge-develop-to-release
Merge Develop into Release
- Loading branch information
Showing
4 changed files
with
231 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
// example key-value: name=%3Cscript%3Econfirm%28%29%3C%2Fscript%3E | ||
function dangerousEchoUsage() { | ||
$name = $_REQUEST['name']; | ||
// ruleid: printed-request | ||
print("Hello : $name"); | ||
// ruleid: printed-request | ||
print("Hello : " . $name); | ||
} | ||
|
||
function safeEchoUsage() { | ||
$name = $_REQUEST['name']; | ||
// ok: printed-request | ||
print("Hello : " . htmlentities($name)); | ||
} | ||
|
||
function doSmth() { | ||
$name = $_REQUEST['name']; | ||
// ruleid: printed-request | ||
print("Hello :".$name); | ||
} | ||
|
||
function doSmth2() { | ||
// ruleid: printed-request | ||
print("Hello ".$_POST['name']." !"); | ||
} | ||
|
||
function doSmth3() { | ||
$name = $_GET['name']; | ||
if (str_contains($name, 'foobar')) { | ||
// ruleid: printed-request | ||
print("Hello :".$name); | ||
} | ||
} | ||
|
||
function doSmth4() { | ||
// ruleid: printed-request | ||
print("Hello ".htmlentities($_POST['name'])." !".$_POST['lastname']); | ||
} | ||
|
||
function doSmth5() { | ||
// ruleid: printed-request | ||
print("Hello ".trim($_POST['name'])); | ||
} | ||
|
||
function doSmth6() { | ||
$VAR = $_GET['someval']; | ||
if(isset($VAR)){ | ||
// ruleid: printed-request | ||
print($VAR); | ||
} | ||
} | ||
|
||
function doSmth7() { | ||
$VAR = $_GET['someval']; | ||
if(empty($VAR)){ | ||
// ruleid: printed-request | ||
print($VAR); | ||
} | ||
} | ||
|
||
function doOK1() { | ||
// ok: printed-request | ||
print("Hello ".htmlentities($_POST['name'])." !"); | ||
} | ||
|
||
function doOK2() { | ||
$input = $_GET['name']; | ||
// ok: printed-request | ||
print("Hello ".htmlspecialchars($input)." !"); | ||
} | ||
|
||
function doOK3() { | ||
$safevar = "Hello ".htmlentities(trim($_GET['name'])); | ||
// ok: printed-request | ||
print($safevar); | ||
} | ||
|
||
function doOK4() { | ||
// ok: printed-request | ||
print("Hello ".e($_POST['name'])." !"); | ||
} | ||
|
||
function doOK5() { | ||
$safevar = esc_attr($_GET['name']); | ||
// ok: printed-request | ||
print("Hello $safevar !"); | ||
} | ||
|
||
function doOK6() { | ||
$safevar = "Hello ".htmlentities($_GET['name']); | ||
// ok: printed-request | ||
print($safevar); | ||
} | ||
|
||
function doOK7() { | ||
$safevar = "Hello ".htmlspecialchars($_GET['name']); | ||
// ok: printed-request | ||
print($safevar); | ||
} | ||
|
||
function doOK8() { | ||
// ok: printed-request | ||
print("Hello ".isset($_POST['name'])." !"); | ||
} | ||
|
||
function doOK9() { | ||
$safevar = empty($_GET['name']); | ||
// ok: printed-request | ||
print("Hello $safevar !"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
rules: | ||
- id: printed-request | ||
mode: taint | ||
message: >- | ||
`Printing user input risks cross-site scripting vulnerability. | ||
You should use `htmlentities()` when showing data to users. | ||
languages: [php] | ||
severity: ERROR | ||
pattern-sources: | ||
- pattern: $_REQUEST | ||
- pattern: $_GET | ||
- pattern: $_POST | ||
pattern-sinks: | ||
- pattern: print($...VARS); | ||
pattern-sanitizers: | ||
- pattern: htmlentities(...) | ||
- pattern: htmlspecialchars(...) | ||
- pattern: strip_tags(...) | ||
- pattern: isset(...) | ||
- pattern: empty(...) | ||
# Wordpress Escapes | ||
- pattern: esc_html(...) | ||
- pattern: esc_attr(...) | ||
- pattern: wp_kses(...) | ||
# Laravel Escapes | ||
- pattern: e(...) | ||
# Symfony Escapes | ||
- pattern: twig_escape_filter(...) | ||
# CodeIgniter Escapes | ||
- pattern: xss_clean(...) | ||
- pattern: html_escape(...) | ||
# Drupal Escapes | ||
- pattern: Html::escape(...) | ||
- pattern: Xss::filter(...) | ||
# Magento Escapes | ||
- pattern: escapeHtml(...) | ||
# Laminas Escapes | ||
- pattern: escapeHtml(...) | ||
- pattern: escapeHtmlAttr(...) | ||
fix: print(htmlentities($...VARS)); | ||
metadata: | ||
technology: | ||
- php | ||
cwe: | ||
- "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" | ||
owasp: | ||
- A07:2017 - Cross-Site Scripting (XSS) | ||
- A03:2021 - Injection | ||
category: security | ||
references: | ||
- https://www.php.net/manual/en/function.htmlentities.php | ||
- https://www.php.net/manual/en/reserved.variables.request.php | ||
- https://www.php.net/manual/en/reserved.variables.post.php | ||
- https://www.php.net/manual/en/reserved.variables.get.php | ||
- https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html | ||
cwe2022-top25: true | ||
cwe2021-top25: true | ||
subcategory: | ||
- vuln | ||
likelihood: MEDIUM | ||
impact: MEDIUM | ||
confidence: MEDIUM |