mirror of
https://github.com/RobustaStudio/semsec.git
synced 2026-11-27 07:47:03 +01:00
Aligns rule metadata with the MIT LICENSE file. Changes "All rights reserved" to "MIT - For the open-source community" across all 262 rules in 13 files. Closes #6
280 lines
9.7 KiB
YAML
280 lines
9.7 KiB
YAML
# ============================================================================
|
|
# Robusta Studio - PHP Web Application Security Rules
|
|
# Copyright (c) 2026 Robusta Studio. All rights reserved.
|
|
#
|
|
# Taint-tracking rules for PHP, Laravel, and WordPress applications.
|
|
# Derived from 60,517 real-world CVE and HackerOne vulnerability records.
|
|
# Dataset: PentesterFlow/OffsecCyber
|
|
#
|
|
# Usage: semgrep --config php-web-taint.yaml /path/to/project
|
|
# ============================================================================
|
|
|
|
rules:
|
|
|
|
# -- CWE-89 | SQL Injection ------------------------------------------------
|
|
|
|
- id: robusta-php-sqli-taint
|
|
mode: taint
|
|
message: >
|
|
Superglobal input flows into SQL query without prepared statement.
|
|
CVE-2023-39650: id param directly in SQL query string.
|
|
Use PDO::prepare() with bound parameters.
|
|
metadata:
|
|
cwe: ["CWE-89"]
|
|
owasp: ["A03:2021 Injection"]
|
|
confidence: HIGH
|
|
impact: HIGH
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
references:
|
|
- https://nvd.nist.gov/vuln/detail/CVE-2023-39650
|
|
severity: ERROR
|
|
languages: [php]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: $_GET[...]
|
|
- pattern: $_POST[...]
|
|
- pattern: $_REQUEST[...]
|
|
- pattern: $_COOKIE[...]
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: mysqli_query($CONN, $Q)
|
|
- pattern: $CONN->query($Q)
|
|
- pattern: $PDO->query($Q)
|
|
- pattern: $PDO->exec($Q)
|
|
- pattern: mysql_query($Q, ...)
|
|
- pattern: $WPDB->query($Q)
|
|
- focus-metavariable: $Q
|
|
pattern-sanitizers:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: intval(...)
|
|
- pattern: mysqli_real_escape_string(...)
|
|
- pattern: $CONN->real_escape_string(...)
|
|
- pattern: $PDO->prepare(...)
|
|
- pattern: $WPDB->prepare(...)
|
|
|
|
# -- CWE-78 | OS Command Injection -----------------------------------------
|
|
|
|
- id: robusta-php-cmdi-taint
|
|
mode: taint
|
|
message: >
|
|
Superglobal input reaches shell execution function.
|
|
Use escapeshellarg() per argument, or avoid shell commands entirely.
|
|
metadata:
|
|
cwe: ["CWE-78"]
|
|
confidence: HIGH
|
|
impact: CRITICAL
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
severity: ERROR
|
|
languages: [php]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: $_GET[...]
|
|
- pattern: $_POST[...]
|
|
- pattern: $_REQUEST[...]
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: system($CMD)
|
|
- pattern: exec($CMD, ...)
|
|
- pattern: passthru($CMD, ...)
|
|
- pattern: shell_exec($CMD)
|
|
- pattern: popen($CMD, ...)
|
|
- pattern: proc_open($CMD, ...)
|
|
- pattern: pcntl_exec($CMD, ...)
|
|
- focus-metavariable: $CMD
|
|
pattern-sanitizers:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: escapeshellarg(...)
|
|
- pattern: escapeshellcmd(...)
|
|
- pattern: intval(...)
|
|
|
|
# -- CWE-98 | Local/Remote File Inclusion ----------------------------------
|
|
|
|
- id: robusta-php-lfi-taint
|
|
mode: taint
|
|
message: >
|
|
User input reaches include/require — enables Local/Remote File Inclusion → RCE.
|
|
CVE-2023-5815: extract($_POST) → include($user_controlled_var) → unauthenticated RCE.
|
|
Validate against an allowlist of expected template paths.
|
|
metadata:
|
|
cwe: ["CWE-98"]
|
|
owasp: ["A03:2021 Injection"]
|
|
confidence: HIGH
|
|
impact: CRITICAL
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
references:
|
|
- https://nvd.nist.gov/vuln/detail/CVE-2023-5815
|
|
severity: ERROR
|
|
languages: [php]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: $_GET[...]
|
|
- pattern: $_POST[...]
|
|
- pattern: $_REQUEST[...]
|
|
- pattern: $_COOKIE[...]
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: include($PATH)
|
|
- pattern: include_once($PATH)
|
|
- pattern: require($PATH)
|
|
- pattern: require_once($PATH)
|
|
- focus-metavariable: $PATH
|
|
pattern-sanitizers:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: basename(...)
|
|
- pattern: realpath(...)
|
|
- pattern: in_array(...)
|
|
|
|
# -- CWE-502 | Insecure Deserialization -------------------------------------
|
|
|
|
- id: robusta-php-deser-taint
|
|
mode: taint
|
|
message: >
|
|
User data reaches unserialize() — enables POP chain → RCE.
|
|
SugarCRM CVE: rest_data POST param → unserialize() without validation.
|
|
Use json_decode() or unserialize($data, ["allowed_classes" => false]).
|
|
metadata:
|
|
cwe: ["CWE-502"]
|
|
owasp: ["A08:2021 Software and Data Integrity Failures"]
|
|
confidence: HIGH
|
|
impact: CRITICAL
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
severity: ERROR
|
|
languages: [php]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: $_GET[...]
|
|
- pattern: $_POST[...]
|
|
- pattern: $_REQUEST[...]
|
|
- pattern: $_COOKIE[...]
|
|
- pattern: file_get_contents("php://input")
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern: unserialize($DATA, ...)
|
|
- focus-metavariable: $DATA
|
|
pattern-sanitizers:
|
|
- patterns:
|
|
- pattern: json_decode(...)
|
|
|
|
# -- CWE-79 | Cross-Site Scripting (XSS) -----------------------------------
|
|
|
|
- id: robusta-php-xss-taint
|
|
mode: taint
|
|
message: >
|
|
Superglobal data output without htmlspecialchars() encoding → reflected XSS.
|
|
CVE-2022-4971: Sassy Social Share plugin 'urls' param reflected without sanitization.
|
|
Encode with htmlspecialchars($input, ENT_QUOTES, 'UTF-8').
|
|
metadata:
|
|
cwe: ["CWE-79"]
|
|
owasp: ["A03:2021 Injection"]
|
|
confidence: HIGH
|
|
impact: HIGH
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
references:
|
|
- https://nvd.nist.gov/vuln/detail/CVE-2022-4971
|
|
severity: ERROR
|
|
languages: [php]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: $_GET[...]
|
|
- pattern: $_POST[...]
|
|
- pattern: $_REQUEST[...]
|
|
- pattern: $_SERVER['HTTP_REFERER']
|
|
- pattern: $_SERVER['REQUEST_URI']
|
|
- pattern: $_SERVER['QUERY_STRING']
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: echo $DATA;
|
|
- pattern: print($DATA);
|
|
- pattern: printf($FMT, ..., $DATA, ...);
|
|
- focus-metavariable: $DATA
|
|
pattern-sanitizers:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: htmlspecialchars(...)
|
|
- pattern: htmlentities(...)
|
|
- pattern: esc_html(...)
|
|
- pattern: esc_attr(...)
|
|
- pattern: wp_kses(...)
|
|
- pattern: strip_tags(...)
|
|
- pattern: intval(...)
|
|
|
|
# -- CWE-918 | Server-Side Request Forgery ----------------------------------
|
|
|
|
- id: robusta-php-ssrf-taint
|
|
mode: taint
|
|
message: >
|
|
User-supplied URL passed to server-side HTTP function. Validate scheme
|
|
(https only), resolve hostname, reject private/metadata IPs.
|
|
metadata:
|
|
cwe: ["CWE-918"]
|
|
owasp: ["A10:2021 Server-Side Request Forgery"]
|
|
confidence: HIGH
|
|
impact: HIGH
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
severity: ERROR
|
|
languages: [php]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: $_GET[...]
|
|
- pattern: $_POST[...]
|
|
- pattern: $_REQUEST[...]
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: file_get_contents($URL)
|
|
- pattern: curl_setopt($CH, CURLOPT_URL, $URL)
|
|
- pattern: fopen($URL, ...)
|
|
- pattern: readfile($URL)
|
|
- pattern: wp_remote_get($URL, ...)
|
|
- pattern: wp_remote_post($URL, ...)
|
|
- focus-metavariable: $URL
|
|
pattern-sanitizers:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: filter_var(..., FILTER_VALIDATE_URL)
|
|
- pattern: wp_http_validate_url(...)
|
|
|
|
# PHP-specific: extract() on superglobals — the CVE-2023-5815 root cause
|
|
# extract($_POST) overwrites local vars → control flow hijack
|
|
|
|
- id: robusta-php-extract-superglobal
|
|
patterns:
|
|
- pattern-either:
|
|
- pattern: extract($_GET, ...)
|
|
- pattern: extract($_POST, ...)
|
|
- pattern: extract($_REQUEST, ...)
|
|
- pattern: extract($_COOKIE, ...)
|
|
message: >
|
|
extract() on a superglobal overwrites local variables with attacker values.
|
|
CVE-2023-5815: extract($_POST) → overwrites template path → include() → RCE.
|
|
Use explicit variable assignment: $var = $_POST['key'].
|
|
metadata:
|
|
cwe: ["CWE-621", "CWE-98"]
|
|
confidence: HIGH
|
|
impact: CRITICAL
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
references:
|
|
- https://nvd.nist.gov/vuln/detail/CVE-2023-5815
|
|
severity: ERROR
|
|
languages: [php]
|