|
| 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