-
-
Notifications
You must be signed in to change notification settings - Fork 2
docs: convert ASCII diagrams to Mermaid with dark-theme colors #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ libmagic-rs is a file type detection library and CLI tool. Its security requirem | |
| | Malicious file author | Exploit the detection tool to gain code execution or cause DoS | Can craft arbitrary file contents | | ||
| | Malicious magic file author | Inject rules that cause crashes, resource exhaustion, or incorrect results | Can craft arbitrary magic rule syntax | | ||
| | Supply chain attacker | Compromise a dependency to inject malicious code | Can publish malicious crate versions | | ||
|
|
||
| ### 2.3 Attack Vectors | ||
|
|
||
| | ID | Vector | Target SR | | ||
|
|
@@ -40,36 +41,38 @@ libmagic-rs is a file type detection library and CLI tool. Its security requirem | |
| | AV-5 | Malformed magic file causes parser crash | SR-2 | | ||
| | AV-6 | CLI argument with path traversal reads unintended files | SR-4 | | ||
| | AV-7 | Compromised dependency introduces unsafe code | SR-5 | | ||
|
|
||
| ## 3. Trust Boundaries | ||
|
|
||
| ```text | ||
| +------------------------------------------------------------------+ | ||
| | Untrusted | | ||
| | +------------------+ +-------------------+ | | ||
| | | Input Files | | Magic Files | | | ||
| | | (any content) | | (user or system) | | | ||
| | +--------+---------+ +--------+----------+ | | ||
| | | | | | ||
| +-----------+-----------------------+-------------------------------+ | ||
| | | | ||
| =========|=======================|============ Trust Boundary ==== | ||
| | | | ||
| +-----------v-----------------------v-------------------------------+ | ||
| | libmagic-rs | | ||
| | | | ||
| | +----------------+ +----------------+ +--------------+ | | ||
| | | Parser | | Evaluator | | Output | | | ||
| | | - validates | | - bounds-check | | - formats | | | ||
| | | magic syntax | | all access | | results | | | ||
| | +----------------+ +----------------+ +--------------+ | | ||
| | | | ||
| | +----------------+ +----------------+ | | ||
| | | I/O Layer | | CLI | | | ||
| | | - mmap files | | - clap args | | | ||
| | | - size limits | | - validates | | | ||
| | +----------------+ +----------------+ | | ||
| +------------------------------------------------------------------+ | ||
| ```mermaid | ||
| flowchart TD | ||
| subgraph Untrusted["Untrusted Zone"] | ||
| direction LR | ||
| IF["Input Files<br/>(any content)"] | ||
| MF["Magic Files<br/>(user or system)"] | ||
| CA["CLI Arguments<br/>(user paths)"] | ||
| end | ||
|
|
||
| subgraph libmagic-rs["libmagic-rs (Trusted Zone)"] | ||
| IO["I/O Layer<br/>mmap files, size limits"] | ||
| CLI["CLI<br/>clap args, validates paths"] | ||
| P["Parser<br/>validates magic syntax"] | ||
| E["Evaluator<br/>bounds-checks all access"] | ||
| O["Output<br/>formats results"] | ||
| end | ||
|
|
||
| IF -- "file bytes" --> IO | ||
| MF -- "magic syntax" --> P | ||
| CA -- "user paths" --> CLI | ||
| IO -- "mapped buffer" --> E | ||
| CLI -- "validated paths" --> IO | ||
| P -- "validated AST" --> E | ||
| E -- "match results" --> O | ||
|
|
||
| style Untrusted fill:#4a1a1a,stroke:#ef5350,color:#e0e0e0,stroke-width:2px | ||
| style libmagic-rs fill:#1b3d1b,stroke:#66bb6a,color:#e0e0e0,stroke-width:2px | ||
|
Comment on lines
+56
to
+73
|
||
| ``` | ||
|
|
||
| All data crossing the trust boundary (file contents, magic file syntax, CLI arguments) is treated as untrusted and validated before use. | ||
|
|
||
| ## 4. Secure Design Principles (Saltzer and Schroeder) | ||
|
|
@@ -84,6 +87,7 @@ All data crossing the trust boundary (file contents, magic file syntax, CLI argu | |
| | **Least privilege** | The tool only reads files; it never writes, executes, or modifies them. No network access. No elevated permissions required. | | ||
| | **Least common mechanism** | No shared mutable state between file evaluations. Each evaluation operates on its own data. No global caches that could leak information. | | ||
| | **Psychological acceptability** | CLI follows GNU `file` conventions. Error messages are descriptive and actionable. Default behavior is safe (built-in rules, no network). | | ||
|
|
||
| ## 5. Common Weakness Countermeasures | ||
|
|
||
| ### 5.1 CWE/SANS Top 25 | ||
|
|
@@ -104,6 +108,7 @@ All data crossing the trust boundary (file contents, magic file syntax, CLI argu | |
| | CWE-190 | Integer overflow | Rust panics on integer overflow in debug builds. Offset calculations use checked arithmetic. | Mitigated | | ||
| | CWE-502 | Deserialization of untrusted data | Magic files are parsed with a strict grammar, not deserialized from arbitrary formats. | Mitigated | | ||
| | CWE-400 | Resource exhaustion | Evaluation timeouts prevent unbounded CPU use. Memory-mapped I/O avoids loading entire files into memory. | Mitigated | | ||
|
|
||
| ### 5.2 OWASP Top 10 (where applicable) | ||
|
|
||
| Most OWASP Top 10 categories target web applications and are not applicable to a file detection library. The applicable items are: | ||
|
|
@@ -114,6 +119,7 @@ Most OWASP Top 10 categories target web applications and are not applicable to a | |
| | A04: Insecure Design | Applicable | Secure design principles applied throughout (see Section 4) | | ||
| | A06: Vulnerable Components | Applicable | `cargo audit` daily, `cargo deny`, Dependabot, `cargo-auditable` | | ||
| | A09: Security Logging | Partial | Evaluation errors logged; security events reported via GitHub Advisories | | ||
|
|
||
| ## 6. Supply Chain Security | ||
|
|
||
| | Measure | Implementation | | ||
|
|
@@ -127,6 +133,7 @@ Most OWASP Top 10 categories target web applications and are not applicable to a | |
| | Binary auditing | `cargo-auditable` embeds dependency metadata in binaries | | ||
| | CI integrity | All GitHub Actions pinned to SHA hashes | | ||
| | Code review | Required on all PRs; automated by CodeRabbit with security-focused checks | | ||
|
|
||
| ## 7. Ongoing Assurance | ||
|
|
||
| This assurance case is maintained as a living document. It is updated when: | ||
|
|
@@ -136,4 +143,4 @@ This assurance case is maintained as a living document. It is updated when: | |
| * Dependencies change significantly | ||
| * Security incidents occur | ||
|
|
||
| The project maintains continuous assurance through automated CI checks (clippy, CodeQL, cargo audit, cargo deny) that run on every commit. | ||
| The project maintains continuous assurance through automated CI checks (clippy, CodeQL, cargo audit, cargo deny) that run on every commit. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#gt;is not a valid HTML escape for>and will render literally in the node labels. If the goal is to avoid Mermaid/Markdown parsing issues with>, use>(or remove the>from the label text) so the diagram renders correctly and matches the PR’s intent of fixing the>-related syntax issue.