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
232 lines
8.8 KiB
YAML
232 lines
8.8 KiB
YAML
# ============================================================================
|
|
# Robusta Studio - Java Web Application Security Rules
|
|
# Copyright (c) 2026 Robusta Studio. All rights reserved.
|
|
#
|
|
# Taint-tracking rules for Java Servlet, Spring Boot, and JEE applications.
|
|
# Derived from 60,517 real-world CVE and HackerOne vulnerability records.
|
|
# Dataset: PentesterFlow/OffsecCyber
|
|
#
|
|
# Usage: semgrep --config java-web-taint.yaml /path/to/project
|
|
# ============================================================================
|
|
|
|
rules:
|
|
|
|
# -- CWE-89 | SQL Injection ------------------------------------------------
|
|
|
|
- id: robusta-java-sqli-taint
|
|
mode: taint
|
|
message: >
|
|
HTTP request parameter concatenated into SQL query via Statement.
|
|
Use PreparedStatement with ? placeholders and setString()/setInt().
|
|
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."
|
|
severity: ERROR
|
|
languages: [java]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: (HttpServletRequest $REQ).getParameter(...)
|
|
- pattern: (HttpServletRequest $REQ).getParameterValues(...)
|
|
- pattern: (HttpServletRequest $REQ).getHeader(...)
|
|
- pattern: (HttpServletRequest $REQ).getQueryString()
|
|
- pattern: (HttpServletRequest $REQ).getPathInfo()
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: (Statement $S).executeQuery($Q)
|
|
- pattern: (Statement $S).execute($Q)
|
|
- pattern: (Statement $S).executeUpdate($Q)
|
|
- pattern: (JdbcTemplate $T).queryForList($Q, ...)
|
|
- pattern: (JdbcTemplate $T).queryForObject($Q, ...)
|
|
- pattern: (JdbcTemplate $T).query($Q, ...)
|
|
- pattern: (JdbcTemplate $T).update($Q, ...)
|
|
- focus-metavariable: $Q
|
|
pattern-sanitizers:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: Integer.parseInt(...)
|
|
- pattern: Long.parseLong(...)
|
|
- pattern: (PreparedStatement $PS).setString(...)
|
|
|
|
# -- CWE-78 | OS Command Injection -----------------------------------------
|
|
|
|
- id: robusta-java-cmdi-taint
|
|
mode: taint
|
|
message: >
|
|
HTTP input reaches Runtime.exec() or ProcessBuilder with shell invocation.
|
|
CVE-2019-0232: Tomcat CGI passes request args to Windows cmd.exe.
|
|
Use ProcessBuilder with explicit argument list (no shell).
|
|
metadata:
|
|
cwe: ["CWE-78"]
|
|
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-2019-0232
|
|
severity: ERROR
|
|
languages: [java]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: (HttpServletRequest $REQ).getParameter(...)
|
|
- pattern: (HttpServletRequest $REQ).getHeader(...)
|
|
- pattern: (HttpServletRequest $REQ).getPathInfo()
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: Runtime.getRuntime().exec($CMD)
|
|
- pattern: Runtime.getRuntime().exec($CMD, ...)
|
|
- pattern: new ProcessBuilder($CMD).start()
|
|
- pattern: new ProcessBuilder("sh", "-c", $CMD)
|
|
- pattern: new ProcessBuilder("cmd", "/c", $CMD)
|
|
- pattern: new ProcessBuilder(Arrays.asList("sh", "-c", $CMD))
|
|
- focus-metavariable: $CMD
|
|
pattern-sanitizers:
|
|
- patterns:
|
|
- pattern: Integer.parseInt(...)
|
|
|
|
# -- CWE-502 | Insecure Deserialization -------------------------------------
|
|
|
|
- id: robusta-java-deser-taint
|
|
mode: taint
|
|
message: >
|
|
HTTP/network data reaches ObjectInputStream without an ObjectInputFilter.
|
|
CVE-2025-53770: SharePoint deserialization RCE (actively exploited).
|
|
Use ObjectInputFilter (Java 9+) with class allowlist, or switch to JSON.
|
|
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."
|
|
references:
|
|
- https://nvd.nist.gov/vuln/detail/CVE-2025-53770
|
|
severity: ERROR
|
|
languages: [java]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: (HttpServletRequest $REQ).getInputStream()
|
|
- pattern: (HttpServletRequest $REQ).getReader()
|
|
- pattern: (Socket $S).getInputStream()
|
|
- pattern: (ServletRequest $REQ).getInputStream()
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: new ObjectInputStream($STREAM)
|
|
- pattern: (ObjectInputStream $OIS).readObject()
|
|
- pattern: (XMLDecoder $D).readObject()
|
|
- focus-metavariable: $STREAM
|
|
|
|
# -- CWE-611 | XML External Entity (XXE) -----------------------------------
|
|
|
|
- id: robusta-java-xxe-unsafe-factory
|
|
patterns:
|
|
- pattern: |
|
|
DocumentBuilderFactory $DBF = DocumentBuilderFactory.newInstance();
|
|
...
|
|
$DBF.newDocumentBuilder().parse($INPUT);
|
|
- pattern-not-inside: |
|
|
DocumentBuilderFactory $DBF = DocumentBuilderFactory.newInstance();
|
|
...
|
|
$DBF.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
|
...
|
|
message: >
|
|
DocumentBuilderFactory parses XML without disabling DOCTYPE declarations.
|
|
Enables XXE to read files, SSRF to internal hosts, or DoS (billion laughs).
|
|
Set setFeature("http://apache.org/xml/features/disallow-doctype-decl", true).
|
|
metadata:
|
|
cwe: ["CWE-611"]
|
|
owasp: ["A05:2021 Security Misconfiguration"]
|
|
confidence: HIGH
|
|
impact: HIGH
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
severity: ERROR
|
|
languages: [java]
|
|
|
|
- id: robusta-java-xxe-saxparser
|
|
patterns:
|
|
- pattern: |
|
|
SAXParserFactory $SPF = SAXParserFactory.newInstance();
|
|
...
|
|
$SPF.newSAXParser().parse($INPUT, ...);
|
|
- pattern-not-inside: |
|
|
SAXParserFactory $SPF = SAXParserFactory.newInstance();
|
|
...
|
|
$SPF.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
|
...
|
|
message: >
|
|
SAXParser without disallow-doctype-decl is vulnerable to XXE.
|
|
metadata:
|
|
cwe: ["CWE-611"]
|
|
confidence: HIGH
|
|
impact: HIGH
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
severity: ERROR
|
|
languages: [java]
|
|
|
|
# -- CWE-917 | Expression Language Injection -------------------------------
|
|
|
|
- id: robusta-java-el-injection-taint
|
|
mode: taint
|
|
message: >
|
|
User input evaluated as an Expression Language expression → RCE.
|
|
Use pre-compiled EL expressions or reject user input in EL context.
|
|
metadata:
|
|
cwe: ["CWE-917"]
|
|
confidence: HIGH
|
|
impact: CRITICAL
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
severity: ERROR
|
|
languages: [java]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: (HttpServletRequest $REQ).getParameter(...)
|
|
- pattern: (HttpServletRequest $REQ).getHeader(...)
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: $PARSER.parseExpression($EXPR)
|
|
- pattern: $FACTORY.createValueExpression($CTX, $EXPR, ...)
|
|
- pattern: $EVAL.evaluate($EXPR, ...)
|
|
- pattern: OgnlUtil.getValue($EXPR, ...)
|
|
- focus-metavariable: $EXPR
|
|
|
|
# -- CWE-90 | LDAP Injection -----------------------------------------------
|
|
|
|
- id: robusta-java-ldapi-taint
|
|
mode: taint
|
|
message: >
|
|
User input concatenated into LDAP search filter. Escape with
|
|
javax.naming.ldap filter encoding or use a parameterized filter builder.
|
|
metadata:
|
|
cwe: ["CWE-90"]
|
|
confidence: HIGH
|
|
impact: HIGH
|
|
author: Robusta Studio
|
|
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
|
|
severity: ERROR
|
|
languages: [java]
|
|
pattern-sources:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: (HttpServletRequest $REQ).getParameter(...)
|
|
pattern-sinks:
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern: (DirContext $CTX).search($BASE, $FILTER, ...)
|
|
- pattern: (InitialDirContext $CTX).search($BASE, $FILTER, ...)
|
|
- pattern: (LdapContext $CTX).search($BASE, $FILTER, ...)
|
|
- focus-metavariable: $FILTER
|