Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,50 @@ Key points:

Many rules under `ruleset/` combine multiple library rules using **`mode: join`**.

Library rules expose their roles through tags:

```yaml
- id: java-ssrf-sink
options:
lib: true
tags:
- ssrf-sink
```

Example (from `ruleset/java/security/ssrf.yaml`):

```yaml
- id: ssrf-in-servlet-app
- id: ssrf
languages:
- java
mode: join
join:
refs:
- rule: java/lib/generic/servlet-untrusted-data-source.yaml#java-servlet-untrusted-data-source
as: untrusted-data
- rule: java/lib/generic/ssrf-sinks.yaml#java-ssrf-sink
- tag: servlet-untrusted-data-source
as: servlet-untrusted-data
- tag: spring-untrusted-data-source
as: spring-untrusted-data
- tag: ssrf-sink
as: sink
on:
- 'untrusted-data.$UNTRUSTED -> sink.$UNTRUSTED'
- 'servlet-untrusted-data.$UNTRUSTED -> sink.$UNTRUSTED'
- 'spring-untrusted-data.$UNTRUSTED -> sink.$UNTRUSTED'
```

Semantics:

- `mode: join` derives a composite rule from other rules referenced in `join.refs`.
- `refs` defines:
- `rule`: path to the library rule file plus `#<rule-id>` inside that YAML
- `as`: local alias for referencing captures/variables from that rule
- `on` describes how to correlate matches from referenced rules:
- `untrusted-data.$UNTRUSTED -> sink.$UNTRUSTED` expresses a **dataflow relationship** between the `$UNTRUSTED` captured in the source rule and the same `$UNTRUSTED` captured in the sink rule.
- Each `ref` selects a library rule and assigns a local alias:
- `tag` selects every enabled rule with that tag in the join's language. Adding the same tag to a
custom rule extends the join.
- `rule` selects one rule by `<path>#<rule-id>`.
- `as` defines the alias used in `on`.
- `on` correlates captures from the referenced rules. For example,
`servlet-untrusted-data.$UNTRUSTED -> sink.$UNTRUSTED` requires dataflow from the source capture
to the sink capture.

Built-in joins use language-scoped, per-source and per-sink tags. Use `rule` when a join must
reference one specific rule.

This join mode is **based on Semgrep's join mode**, but OpenTaint extends it with custom features (such as the `->` notation in the `on` section) to express taint-style flows across multiple rule components.

Expand Down Expand Up @@ -227,7 +246,8 @@ When introducing or changing rules, follow these guidelines:
- Add `options.lib: true` for library fragments in `lib/` (or exceptionally in `ruleset/` if they are not meant to be executed directly).

3. **Avoid duplicates**
- Reuse existing library rules from `lib/` and compose them via `mode: join` where applicable.
- Reuse library rules from `lib/` and compose them with `mode: join` where applicable.
- Reference join sources and sinks by `tag`, and tag each new library source or sink.

4. **Update tests**
- Add at least one `@PositiveRuleSample` (and typically `@NegativeRuleSample`) under `test/src/main/java/security/`.
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/cmdi-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: cmdi-sinks
options:
lib: true
tags:
- command-injection-sink
severity: NOTE
message: Untrusted data reaches an OS command execution API
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/http-sources-header-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: http-sources-header-index
options:
lib: true
tags:
- beego-header-untrusted-data-source
severity: NOTE
message: Untrusted beego request-header value source
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/http-sources-requesturi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: http-sources-requesturi
options:
lib: true
tags:
- request-uri-untrusted-data-source
severity: NOTE
message: Untrusted request URI source
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/http-sources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: http-sources
options:
lib: true
tags:
- http-untrusted-data-source
severity: NOTE
message: Untrusted user input originates here
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/path-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: path-sinks
options:
lib: true
tags:
- path-traversal-sink
severity: NOTE
message: Untrusted data reaches a filesystem path API
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/sql-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: sql-sinks
options:
lib: true
tags:
- sqli-sink
severity: NOTE
message: Untrusted data reaches a SQL execution API
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/ssrf-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: ssrf-sinks
options:
lib: true
tags:
- ssrf-sink
severity: NOTE
message: Untrusted data reaches an outbound HTTP request API
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/ssti-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: ssti-sinks
options:
lib: true
tags:
- ssti-sink
severity: NOTE
message: Untrusted data reaches a template-source parse API
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/go/lib/xss-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: xss-sinks
options:
lib: true
tags:
- xss-sink
severity: NOTE
message: Untrusted data reaches an HTTP response write API
metadata:
Expand Down
6 changes: 3 additions & 3 deletions rules/ruleset/go/security/cmdinj.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ rules:
mode: join
join:
refs:
- rule: go/lib/http-sources.yaml#http-sources
- tag: http-untrusted-data-source
as: src
- rule: go/lib/http-sources-header-index.yaml#http-sources-header-index
- tag: beego-header-untrusted-data-source
as: extra_header
- rule: go/lib/cmdi-sinks.yaml#cmdi-sinks
- tag: command-injection-sink
as: sink
on:
- 'src.$UNTRUSTED -> sink.$UNTRUSTED'
Expand Down
4 changes: 2 additions & 2 deletions rules/ruleset/go/security/path-traversal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ rules:
mode: join
join:
refs:
- rule: go/lib/http-sources.yaml#http-sources
- tag: http-untrusted-data-source
as: src
- rule: go/lib/path-sinks.yaml#path-sinks
- tag: path-traversal-sink
as: sink
on:
- 'src.$UNTRUSTED -> sink.$UNTRUSTED'
8 changes: 4 additions & 4 deletions rules/ruleset/go/security/sql-injection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ rules:
mode: join
join:
refs:
- rule: go/lib/http-sources.yaml#http-sources
- tag: http-untrusted-data-source
as: src
- rule: go/lib/http-sources-requesturi.yaml#http-sources-requesturi
- tag: request-uri-untrusted-data-source
as: extra_requesturi
- rule: go/lib/http-sources-header-index.yaml#http-sources-header-index
- tag: beego-header-untrusted-data-source
as: extra_header
- rule: go/lib/sql-sinks.yaml#sql-sinks
- tag: sqli-sink
as: sink
on:
- 'src.$UNTRUSTED -> sink.$UNTRUSTED'
Expand Down
4 changes: 2 additions & 2 deletions rules/ruleset/go/security/ssrf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ rules:
mode: join
join:
refs:
- rule: go/lib/http-sources.yaml#http-sources
- tag: http-untrusted-data-source
as: src
- rule: go/lib/ssrf-sinks.yaml#ssrf-sinks
- tag: ssrf-sink
as: sink
on:
- 'src.$UNTRUSTED -> sink.$UNTRUSTED'
4 changes: 2 additions & 2 deletions rules/ruleset/go/security/ssti.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ rules:
mode: join
join:
refs:
- rule: go/lib/http-sources.yaml#http-sources
- tag: http-untrusted-data-source
as: src
- rule: go/lib/ssti-sinks.yaml#ssti-sinks
- tag: ssti-sink
as: sink
on:
- 'src.$UNTRUSTED -> sink.$UNTRUSTED'
4 changes: 2 additions & 2 deletions rules/ruleset/go/security/xss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ rules:
mode: join
join:
refs:
- rule: go/lib/http-sources.yaml#http-sources
- tag: http-untrusted-data-source
as: src
- rule: go/lib/xss-sinks.yaml#xss-sinks
- tag: xss-sink
as: sink
on:
- 'src.$UNTRUSTED -> sink.$UNTRUSTED'
6 changes: 6 additions & 0 deletions rules/ruleset/java/lib/generic/code-injection-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: ognl-injection-sinks
options:
lib: true
tags:
- ognl-injection-sink
severity: NOTE
message: Untrusted input reaches OGNL expression
metadata:
Expand Down Expand Up @@ -54,6 +56,8 @@ rules:
- id: dangerous-groovy-shell
options:
lib: true
tags:
- groovy-injection-sink
severity: NOTE
message: Groovy shell run of externally-manipulated script
metadata:
Expand Down Expand Up @@ -84,6 +88,8 @@ rules:
- id: dangerous-script-engine-eval
options:
lib: true
tags:
- script-engine-injection-sink
severity: NOTE
message: Risky code evaluation with user-controled value
metadata:
Expand Down
4 changes: 4 additions & 0 deletions rules/ruleset/java/lib/generic/command-injection-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: command-injection-sinks
options:
lib: true
tags:
- command-injection-sink
severity: NOTE
message: Executing OS command with user-controlled data
metadata:
Expand Down Expand Up @@ -46,6 +48,8 @@ rules:
- id: java-expression-language-sinks
options:
lib: true
tags:
- el-injection-sink
severity: NOTE
message: Java EL evaluation directly with user-supplied input
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-xpath-injection-sinks
options:
lib: true
tags:
- xpath-injection-sink
severity: NOTE
message: XPath query contains user-manipulated data
metadata:
Expand All @@ -21,6 +23,8 @@ rules:
- id: java-mongodb-nosql-injection
options:
lib: true
tags:
- mongodb-injection-sink
severity: NOTE
message: >-
User-controled data passed into a NoSQL query using the 'where' evaluation operator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-http-response-splitting-sink
options:
lib: true
tags:
- http-response-splitting-sink
severity: NOTE
message: Improper neutralization of CRLF sequences in HTTP headers
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/java/lib/generic/ldap-injection-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-ldap-injection-sinks
options:
lib: true
tags:
- ldap-injection-sink
severity: NOTE
message: Call of LDAP injection-sensitive function with untrusted data.
metadata:
Expand Down
4 changes: 4 additions & 0 deletions rules/ruleset/java/lib/generic/logging-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-logging-sinks
options:
lib: true
tags:
- log-injection-sink
severity: NOTE
message: Logging the data
metadata:
Expand Down Expand Up @@ -33,6 +35,8 @@ rules:
- id: seam-log-injection-sinks
options:
lib: true
tags:
- seam-log-injection-sink
severity: NOTE
message: Potential injection into Seam logging expression language
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/java/lib/generic/path-traversal-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-path-traversal-sinks
options:
lib: true
tags:
- path-traversal-sink
severity: NOTE
message: Use a file with untrusted path
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: seam-untrusted-data-source
options:
lib: true
tags:
- seam-untrusted-data-source
message: Untrusted data flows from here
severity: NOTE
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-servlet-response-injection-sink
options:
lib: true
tags:
- servlet-response-injection-sink
severity: NOTE
message: Direct write of unvalidated user input into response
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-servlet-untrusted-data-source
options:
lib: true
tags:
- servlet-untrusted-data-source
severity: NOTE
message: Untrusted data flows from here
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-servlet-unvalidated-redirect-sinks
options:
lib: true
tags:
- servlet-unvalidated-redirect-sink
severity: NOTE
message: Potential redirect to an untrusted URL
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-servlet-xss-html-response-sink
options:
lib: true
tags:
- servlet-xss-sink
severity: NOTE
message: Direct write of unvalidated user input into a response without safe content type
metadata:
Expand Down
2 changes: 2 additions & 0 deletions rules/ruleset/java/lib/generic/smtp-injection-sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ rules:
- id: java-smtp-crlf-injection-sinks
options:
lib: true
tags:
- smtp-injection-sink
severity: NOTE
message: Unvalidated user-manipulated data reaches sensitive MimeMessage parts
metadata:
Expand Down
Loading
Loading