Skip to content

Commit c3ea4c0

Browse files
committed
Add pattern registries for php, csharp, swift, dart, elixir, perl
Expands ecosystem coverage from 6 to 12 with source→sink→guard vulnerability patterns for each new language. Updates release_check.py to validate all 12 ecosystems.
1 parent c29dd1b commit c3ea4c0

19 files changed

Lines changed: 595 additions & 1 deletion

File tree

scripts/release_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def validate_pattern_registry() -> None:
132132
"CWE:",
133133
]
134134
root = REPO_ROOT / "shared" / "references" / "patterns"
135-
for ecosystem in ["npm", "python", "go", "rust", "java", "ruby"]:
135+
for ecosystem in ["npm", "python", "go", "rust", "java", "ruby", "php", "csharp", "swift", "dart", "elixir", "perl"]:
136136
path = root / f"{ecosystem}.md"
137137
if not path.exists():
138138
raise SystemExit(f"missing pattern registry: {path.relative_to(REPO_ROOT)}")
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# C# Vulnerability Pattern Registry
2+
3+
Use these entries as audit methods. Do not treat them as examples of any specific real package.
4+
5+
## Deserialization: BinaryFormatter/ObjectStateFormatter
6+
7+
- Source pattern: HTTP body, ViewState, cookie, message queue payload, or file content reaches a deserialization call.
8+
- Sink signature: `BinaryFormatter.Deserialize(stream)`, `ObjectStateFormatter.Deserialize(data)`, `NetDataContractSerializer.ReadObject(reader)`.
9+
- Common misuse: untrusted byte stream is deserialized with a formatter that allows arbitrary type instantiation.
10+
- Expected guard: use `System.Text.Json` or `JsonSerializer` with known types, avoid BinaryFormatter entirely, or implement strict `SerializationBinder` with type allowlist.
11+
- Evidence criteria: show untrusted data source, formatter instantiation, Deserialize call, and missing type restriction or binder.
12+
- False-positive checks: data source is trusted internal, custom binder restricts types, formatter is used only for trusted IPC, or code targets .NET 8+ where BinaryFormatter is removed.
13+
- CWE: CWE-502
14+
15+
## Path traversal: Path.Combine
16+
17+
- Source pattern: HTTP parameter, uploaded filename, API input, or config value controls a path segment passed to file operations.
18+
- Sink signature: `Path.Combine(basePath, userInput)`, `File.ReadAllText(path)`, `File.WriteAllBytes(path, data)`.
19+
- Common misuse: `Path.Combine` with an absolute user path ignores the base directory; no canonical path check follows.
20+
- Expected guard: use `Path.GetFullPath` and verify result starts with intended base directory, reject absolute paths and `..` segments.
21+
- Evidence criteria: show user input source, Path.Combine or concatenation, file I/O sink, and missing containment validation.
22+
- False-positive checks: input is validated against allowlist, path is resolved and base-checked, or file operation is read-only on public content.
23+
- CWE: CWE-22
24+
25+
## SSRF: HttpClient with user URL
26+
27+
- Source pattern: HTTP parameter, webhook config, callback URL, or integration setting controls a URL passed to HttpClient.
28+
- Sink signature: `HttpClient.GetAsync(userUrl)`, `HttpClient.SendAsync(request)`, `WebClient.DownloadString(url)`.
29+
- Common misuse: user-controlled URL is fetched without scheme validation, hostname allowlist, or private IP filtering.
30+
- Expected guard: parse URL, enforce https scheme, validate hostname against allowlist, resolve DNS and reject private/loopback ranges, limit redirects.
31+
- Evidence criteria: show URL source, HttpClient call, and missing scheme/host/IP validation.
32+
- False-positive checks: URL is from trusted config, hostname is hardcoded, proxy handles validation, or request is to a fixed internal service.
33+
- CWE: CWE-918

shared/references/patterns/dart.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Dart Vulnerability Pattern Registry
2+
3+
Use these entries as audit methods. Do not treat them as examples of any specific real package.
4+
5+
## Path traversal: file serving
6+
7+
- Source pattern: HTTP request path, user-provided filename, or API parameter controls a file path in a server-side Dart application.
8+
- Sink signature: `File(path).readAsBytes()`, `File(path).readAsString()`, `shelf_static` handler with user path.
9+
- Common misuse: user-controlled path segment is joined to a base directory without canonicalization or containment check.
10+
- Expected guard: resolve canonical path, verify it starts with intended base, reject `..` and absolute paths, use `Uri.normalizePath`.
11+
- Evidence criteria: show user input source, path construction, file I/O sink, and missing containment validation.
12+
- False-positive checks: path is from hardcoded asset list, static file handler has built-in traversal protection, or input is validated against allowlist.
13+
- CWE: CWE-22
14+
15+
## SSRF: http.get with user URL
16+
17+
- Source pattern: user input, webhook URL, or external config controls a URL passed to Dart HTTP client.
18+
- Sink signature: `http.get(Uri.parse(userUrl))`, `HttpClient().getUrl(Uri.parse(url))`, `Dio().get(url)`.
19+
- Common misuse: user-controlled URL is fetched without scheme restriction, hostname validation, or private IP filtering.
20+
- Expected guard: parse URI, enforce https scheme, validate hostname against allowlist, resolve DNS and reject private ranges.
21+
- Evidence criteria: show URL source, HTTP client call, and missing scheme/host validation.
22+
- False-positive checks: URL is from trusted config, hostname is hardcoded, or request goes through a validated proxy.
23+
- CWE: CWE-918
24+
25+
## Command injection: Process.run
26+
27+
- Source pattern: user input, filename, or external parameter is interpolated into a shell command string.
28+
- Sink signature: `Process.run(executable, arguments)`, `Process.start(cmd, args)` with shell: true.
29+
- Common misuse: user-controlled string is passed as shell command or unsanitized argument with `runInShell: true`.
30+
- Expected guard: avoid `runInShell: true`, pass arguments as list elements (not interpolated strings), validate input against allowlist.
31+
- Evidence criteria: show user input source, Process.run call with shell mode or string interpolation, and missing input sanitization.
32+
- False-positive checks: arguments are from trusted enum, shell mode is disabled, or input is numeric-only.
33+
- CWE: CWE-78
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Elixir Vulnerability Pattern Registry
2+
3+
Use these entries as audit methods. Do not treat them as examples of any specific real package.
4+
5+
## Code injection: Code.eval_string
6+
7+
- Source pattern: HTTP parameter, WebSocket message, config value, or template variable reaches a dynamic code evaluation function.
8+
- Sink signature: `Code.eval_string(user_input)`, `Code.eval_quoted(ast)`, `:erlang.binary_to_term(data)`.
9+
- Common misuse: user-controlled string is evaluated as Elixir/Erlang code without sandboxing or input restriction.
10+
- Expected guard: avoid dynamic code evaluation entirely, use pattern matching on known commands, or restrict to compile-time macros.
11+
- Evidence criteria: show user input source, eval call site, and missing input validation or sandboxing.
12+
- False-positive checks: input is from admin-only LiveView, eval is compile-time only, or input is validated against a fixed command set.
13+
- CWE: CWE-94
14+
15+
## Atom exhaustion: String.to_atom
16+
17+
- Source pattern: HTTP parameter, JSON key, or external input is converted to an atom without bounds checking.
18+
- Sink signature: `String.to_atom(user_input)`, `:"#{user_input}"`, `List.to_atom(charlist)`.
19+
- Common misuse: unbounded user input creates atoms, which are never garbage collected, leading to VM memory exhaustion.
20+
- Expected guard: use `String.to_existing_atom/1` which raises on unknown atoms, or validate input against a known set before conversion.
21+
- Evidence criteria: show user input source, to_atom call, and missing existing_atom guard or input validation.
22+
- False-positive checks: input is from a fixed enum, to_existing_atom is used, or atom creation is bounded by application logic.
23+
- CWE: CWE-400
24+
25+
## SQL injection: raw Ecto query
26+
27+
- Source pattern: HTTP parameter, search query, or filter value is interpolated into a raw SQL fragment in Ecto.
28+
- Sink signature: `Ecto.Adapters.SQL.query(repo, "SELECT ... #{input}")`, `fragment("... #{input} ...")`.
29+
- Common misuse: user input is string-interpolated into raw SQL fragments instead of using parameterized placeholders.
30+
- Expected guard: use `fragment("... ? ...", ^input)` with pinned variables, or Ecto query builder with automatic parameterization.
31+
- Evidence criteria: show user input source, string interpolation in SQL/fragment, and missing parameterization.
32+
- False-positive checks: input is cast to integer, fragment uses ? placeholders with pinned values, or query builder handles escaping.
33+
- CWE: CWE-89

shared/references/patterns/perl.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Perl Vulnerability Pattern Registry
2+
3+
Use these entries as audit methods. Do not treat them as examples of any specific real package.
4+
5+
## Command injection: open/system with user input
6+
7+
- Source pattern: CGI parameter, form field, filename, or environment variable is interpolated into a shell command or two-argument open.
8+
- Sink signature: `system("cmd $input")`, `open(FH, "| $input")`, `` `$cmd $input` ``, `exec("$cmd $input")`.
9+
- Common misuse: user-controlled string is interpolated into shell commands without escaping or argument list form.
10+
- Expected guard: use list-form system/exec (`system("cmd", @args)`), avoid shell interpolation, validate input against allowlist.
11+
- Evidence criteria: show user input source, shell interpolation in command string, execution sink, and missing sanitization.
12+
- False-positive checks: input is from trusted source, command uses list form, or input is validated against fixed set.
13+
- CWE: CWE-78
14+
15+
## Path traversal: open with user path
16+
17+
- Source pattern: CGI parameter, uploaded filename, or URL path segment controls a file path in an open call.
18+
- Sink signature: `open(FH, "<$path")`, `open(FH, $path)`, `read_file($path)`.
19+
- Common misuse: user-controlled path is opened without canonicalization, containment check, or null byte filtering.
20+
- Expected guard: canonicalize with `Cwd::realpath`, verify path starts with base directory, reject `..` and null bytes, use three-argument open.
21+
- Evidence criteria: show user input source, open call with user path, and missing containment validation.
22+
- False-positive checks: path is from hardcoded list, realpath check is applied, or file is in read-only public directory.
23+
- CWE: CWE-22
24+
25+
## Regex denial of service: user-controlled pattern
26+
27+
- Source pattern: HTTP parameter, search field, or config value is used as a regex pattern or matched against a vulnerable regex.
28+
- Sink signature: `$input =~ /$user_regex/`, `qr/$user_pattern/`, regex with nested quantifiers on user input.
29+
- Common misuse: user-controlled regex or input matched against exponential-backtracking pattern causes CPU exhaustion.
30+
- Expected guard: use `re::engine::RE2` for user patterns, set match timeout, limit input length, or avoid user-controlled regex.
31+
- Evidence criteria: show user input reaching regex compilation or matching, pattern with catastrophic backtracking potential, and missing timeout/length guard.
32+
- False-positive checks: regex is fixed/hardcoded, input length is bounded, or RE2 engine is used.
33+
- CWE: CWE-1333

shared/references/patterns/php.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# PHP Vulnerability Pattern Registry
2+
3+
Use these entries as audit methods. Do not treat them as examples of any specific real package.
4+
5+
## Object injection: unserialize
6+
7+
- Source pattern: HTTP body, cookie, session data, or database value reaches an unserialize call.
8+
- Sink signature: `unserialize($userInput)`, `igbinary_unserialize($data)`.
9+
- Common misuse: attacker-controlled serialized string is deserialized without class allowlist, enabling magic method chains.
10+
- Expected guard: use `json_decode` instead, or pass `allowed_classes: []` option to `unserialize`, or validate input format before deserialization.
11+
- Evidence criteria: show source of serialized data, unserialize call site, available gadget classes with `__wakeup`/`__destruct`, and missing allowed_classes restriction.
12+
- False-positive checks: input is from trusted internal source, allowed_classes is restricted, no exploitable gadget chain exists, or input is validated as JSON.
13+
- CWE: CWE-502
14+
15+
## SQL injection: query interpolation
16+
17+
- Source pattern: HTTP parameter, form field, URL segment, or header value is interpolated into a SQL query string.
18+
- Sink signature: `$pdo->query("... $input ...")`, `mysqli_query($conn, "... $input ...")`, `DB::raw($input)`.
19+
- Common misuse: user input is concatenated or interpolated into SQL without parameterized queries or proper escaping.
20+
- Expected guard: use prepared statements with bound parameters, or ORM query builder with automatic escaping.
21+
- Evidence criteria: show user input source, string interpolation into SQL, query execution sink, and absence of parameter binding.
22+
- False-positive checks: input is cast to integer, query uses prepared statements, input comes from trusted enum, or ORM handles escaping.
23+
- CWE: CWE-89
24+
25+
## Remote code execution: eval/system
26+
27+
- Source pattern: HTTP parameter, uploaded filename, template variable, or config value reaches a code execution function.
28+
- Sink signature: `eval($code)`, `system($cmd)`, `exec($cmd)`, `passthru($cmd)`, `shell_exec($cmd)`, `proc_open($cmd)`, `preg_replace('/e', ...)`.
29+
- Common misuse: user-controlled string is passed to code or command execution without sanitization or allowlisting.
30+
- Expected guard: avoid dynamic code execution entirely, use allowlisted commands with escapeshellarg, or sandbox with restricted function list.
31+
- Evidence criteria: show user input source, path to execution function, and missing input validation or command construction guard.
32+
- False-positive checks: input is from admin-only interface, command is static with no user segments, or execution is disabled by PHP configuration.
33+
- CWE: CWE-78
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Swift Vulnerability Pattern Registry
2+
3+
Use these entries as audit methods. Do not treat them as examples of any specific real package.
4+
5+
## Path traversal: URL/path construction
6+
7+
- Source pattern: HTTP parameter, user input field, filename from API response, or deep link parameter controls a file path.
8+
- Sink signature: `FileManager.default.contents(atPath:)`, `Data(contentsOf: url)`, `String(contentsOfFile:)`.
9+
- Common misuse: user-controlled path component is appended to a base URL/path without canonicalization or containment check.
10+
- Expected guard: resolve symbolic links, canonicalize path, verify resolved path is within intended sandbox directory, reject `..` components.
11+
- Evidence criteria: show user input source, path construction, file read/write sink, and missing containment validation.
12+
- False-positive checks: path is from app bundle (read-only), input is validated against enum, or sandbox prevents escape.
13+
- CWE: CWE-22
14+
15+
## Insecure TLS: disabled certificate validation
16+
17+
- Source pattern: URLSession delegate, Alamofire ServerTrustManager, or custom TLS configuration disables certificate validation.
18+
- Sink signature: `urlSession(_:didReceive challenge:)` returning `.useCredential` unconditionally, `ServerTrustManager(evaluators: [host: DisabledTrustEvaluator()])`.
19+
- Common misuse: certificate validation is disabled for all hosts or production builds, enabling MITM attacks.
20+
- Expected guard: only disable for specific debug hosts behind compile-time flags, use certificate pinning for sensitive endpoints.
21+
- Evidence criteria: show trust evaluation override, scope of disabled validation, and absence of build-configuration guard.
22+
- False-positive checks: disabled only in DEBUG builds, limited to local development hosts, or pinning is applied for production.
23+
- CWE: CWE-295
24+
25+
## SQL injection: raw query in Core Data/SQLite
26+
27+
- Source pattern: user input from text field, search query, or URL parameter is interpolated into a raw SQL or NSPredicate string.
28+
- Sink signature: `sqlite3_exec(db, "SELECT ... \(input) ...")`, `NSPredicate(format: "name == '\(input)'")`.
29+
- Common misuse: string interpolation in SQL or predicate format strings without parameterization.
30+
- Expected guard: use `?` placeholders with `sqlite3_bind_text`, or `NSPredicate(format:argumentArray:)` with `%@` substitution.
31+
- Evidence criteria: show user input source, string interpolation in query/predicate, execution sink, and missing parameterization.
32+
- False-positive checks: input is numeric-only, query uses bound parameters, or predicate uses %@ with argument array.
33+
- CWE: CWE-89
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# C# Vulnerability Pattern Registry
2+
3+
Use these entries as audit methods. Do not treat them as examples of any specific real package.
4+
5+
## Deserialization: BinaryFormatter/ObjectStateFormatter
6+
7+
- Source pattern: HTTP body, ViewState, cookie, message queue payload, or file content reaches a deserialization call.
8+
- Sink signature: `BinaryFormatter.Deserialize(stream)`, `ObjectStateFormatter.Deserialize(data)`, `NetDataContractSerializer.ReadObject(reader)`.
9+
- Common misuse: untrusted byte stream is deserialized with a formatter that allows arbitrary type instantiation.
10+
- Expected guard: use `System.Text.Json` or `JsonSerializer` with known types, avoid BinaryFormatter entirely, or implement strict `SerializationBinder` with type allowlist.
11+
- Evidence criteria: show untrusted data source, formatter instantiation, Deserialize call, and missing type restriction or binder.
12+
- False-positive checks: data source is trusted internal, custom binder restricts types, formatter is used only for trusted IPC, or code targets .NET 8+ where BinaryFormatter is removed.
13+
- CWE: CWE-502
14+
15+
## Path traversal: Path.Combine
16+
17+
- Source pattern: HTTP parameter, uploaded filename, API input, or config value controls a path segment passed to file operations.
18+
- Sink signature: `Path.Combine(basePath, userInput)`, `File.ReadAllText(path)`, `File.WriteAllBytes(path, data)`.
19+
- Common misuse: `Path.Combine` with an absolute user path ignores the base directory; no canonical path check follows.
20+
- Expected guard: use `Path.GetFullPath` and verify result starts with intended base directory, reject absolute paths and `..` segments.
21+
- Evidence criteria: show user input source, Path.Combine or concatenation, file I/O sink, and missing containment validation.
22+
- False-positive checks: input is validated against allowlist, path is resolved and base-checked, or file operation is read-only on public content.
23+
- CWE: CWE-22
24+
25+
## SSRF: HttpClient with user URL
26+
27+
- Source pattern: HTTP parameter, webhook config, callback URL, or integration setting controls a URL passed to HttpClient.
28+
- Sink signature: `HttpClient.GetAsync(userUrl)`, `HttpClient.SendAsync(request)`, `WebClient.DownloadString(url)`.
29+
- Common misuse: user-controlled URL is fetched without scheme validation, hostname allowlist, or private IP filtering.
30+
- Expected guard: parse URL, enforce https scheme, validate hostname against allowlist, resolve DNS and reject private/loopback ranges, limit redirects.
31+
- Evidence criteria: show URL source, HttpClient call, and missing scheme/host/IP validation.
32+
- False-positive checks: URL is from trusted config, hostname is hardcoded, proxy handles validation, or request is to a fixed internal service.
33+
- CWE: CWE-918

0 commit comments

Comments
 (0)