torusguard 1.0.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.torusguard/.manifest.json +89 -75
  2. package/.torusguard/references/csharp-security.md +41 -0
  3. package/.torusguard/references/go-security.md +41 -0
  4. package/.torusguard/references/java-security.md +40 -0
  5. package/.torusguard/references/polyglot-security-matrix.md +25 -0
  6. package/.torusguard/references/rust-security.md +40 -0
  7. package/.torusguard/rules/custom/.gitkeep +1 -0
  8. package/.torusguard/rules/custom/README.md +30 -0
  9. package/.torusguard/runs/report-latest.html +328 -0
  10. package/.torusguard/schemas/golden-recipe.schema.json +75 -0
  11. package/.torusguard/scripts/diff_guard.py +131 -4
  12. package/.torusguard/scripts/finding_scorer.py +33 -5
  13. package/.torusguard/scripts/html_reporter.py +628 -0
  14. package/.torusguard/scripts/manifest_builder.py +5 -5
  15. package/.torusguard/scripts/memory_engine.py +521 -99
  16. package/.torusguard/scripts/monorepo_detector.py +123 -10
  17. package/.torusguard/scripts/rules_sync.py +321 -0
  18. package/.torusguard/scripts/stack_detect.py +458 -26
  19. package/.torusguard/skills/torusguard/references/csharp-security.md +41 -0
  20. package/.torusguard/skills/torusguard/references/go-security.md +41 -0
  21. package/.torusguard/skills/torusguard/references/java-security.md +40 -0
  22. package/.torusguard/skills/torusguard/references/polyglot-security-matrix.md +25 -0
  23. package/.torusguard/skills/torusguard/references/rust-security.md +40 -0
  24. package/README.md +307 -410
  25. package/bin/torusguard.js +108 -4
  26. package/package.json +1 -1
  27. package/skills/torusguard/bootstrap.py +2 -2
  28. package/skills/torusguard/payload/.manifest.json +89 -75
  29. package/skills/torusguard/payload/references/csharp-security.md +41 -0
  30. package/skills/torusguard/payload/references/go-security.md +41 -0
  31. package/skills/torusguard/payload/references/java-security.md +40 -0
  32. package/skills/torusguard/payload/references/polyglot-security-matrix.md +25 -0
  33. package/skills/torusguard/payload/references/rust-security.md +40 -0
  34. package/skills/torusguard/payload/rules/custom/.gitkeep +1 -0
  35. package/skills/torusguard/payload/rules/custom/README.md +30 -0
  36. package/skills/torusguard/payload/schemas/golden-recipe.schema.json +75 -0
  37. package/skills/torusguard/payload/scripts/diff_guard.py +131 -4
  38. package/skills/torusguard/payload/scripts/finding_scorer.py +33 -5
  39. package/skills/torusguard/payload/scripts/html_reporter.py +628 -0
  40. package/skills/torusguard/payload/scripts/manifest_builder.py +5 -5
  41. package/skills/torusguard/payload/scripts/memory_engine.py +521 -99
  42. package/skills/torusguard/payload/scripts/monorepo_detector.py +123 -10
  43. package/skills/torusguard/payload/scripts/rules_sync.py +321 -0
  44. package/skills/torusguard/payload/scripts/stack_detect.py +458 -26
  45. package/skills/torusguard/payload/skills/torusguard/bootstrap.py +2 -2
  46. package/skills/torusguard/payload/skills/torusguard/references/csharp-security.md +41 -0
  47. package/skills/torusguard/payload/skills/torusguard/references/go-security.md +41 -0
  48. package/skills/torusguard/payload/skills/torusguard/references/java-security.md +40 -0
  49. package/skills/torusguard/payload/skills/torusguard/references/polyglot-security-matrix.md +25 -0
  50. package/skills/torusguard/payload/skills/torusguard/references/rust-security.md +40 -0
  51. package/.torusguard/scripts/__pycache__/diff_guard.cpython-311.pyc +0 -0
  52. package/.torusguard/scripts/__pycache__/finding_scorer.cpython-311.pyc +0 -0
  53. package/.torusguard/scripts/__pycache__/memory_engine.cpython-311.pyc +0 -0
  54. package/.torusguard/scripts/__pycache__/monorepo_detector.cpython-311.pyc +0 -0
  55. package/skills/torusguard/__pycache__/bootstrap.cpython-311.pyc +0 -0
@@ -0,0 +1,41 @@
1
+ # TorusGuard Skill Reference: Go Security
2
+
3
+ > **Loaded When:** A project is identified as a Go application (`go.mod`, `go.sum`, or Go source files detected).
4
+
5
+ ---
6
+
7
+ ## 🛡️ Key Inspection Areas & Rules
8
+
9
+ ### 1. Database & SQL Injection
10
+ * `TG-INPUT-002`: Ensure raw queries use parameterized placeholders (`?`, `$1`), never `fmt.Sprintf` or string concatenation.
11
+ * `TG-DB-004`: Enforce tenant isolation in GORM queries (`db.Where("tenant_id = ?", tenantID)`).
12
+
13
+ ### 2. TLS & Network Security
14
+ * `TG-DIFF-001`: Prohibit `InsecureSkipVerify: true` in `tls.Config`. Always use valid root CA pools.
15
+ * `TG-SSRF-001`: Validate outbound URLs before issuing `http.Get` or `http.Post`.
16
+
17
+ ### 3. Concurrency & Goroutine Safety
18
+ * `TG-BIZ-001`: Ensure context cancellation propagation (`ctx.Done()`) to prevent goroutine leaks.
19
+ * Use mutexes or channels to prevent data races on shared state.
20
+
21
+ ### 4. Input Validation & Path Traversal
22
+ * `TG-INPUT-006`: Sanitize file paths with `filepath.Clean` and check `strings.HasPrefix(cleanPath, baseDir)`.
23
+
24
+ ---
25
+
26
+ ## 🛠️ Safe Patterns Summary
27
+
28
+ ```go
29
+ // Safe Parameterized Query
30
+ row := db.QueryRowContext(ctx, "SELECT id, email FROM users WHERE id = ? AND tenant_id = ?", userID, tenantID)
31
+
32
+ // Safe GORM Scoping
33
+ var invoice Invoice
34
+ result := db.Where("id = ? AND tenant_id = ?", invoiceID, currentTenantID).First(&invoice)
35
+
36
+ // Safe TLS Client
37
+ tlsConfig := &tls.Config{
38
+ MinVersion: tls.VersionTLS13,
39
+ }
40
+ client := &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}}
41
+ ```
@@ -0,0 +1,40 @@
1
+ # TorusGuard Skill Reference: Java & Spring Security
2
+
3
+ > **Loaded When:** A project is identified as a Java/Kotlin application (`pom.xml`, `build.gradle`, Spring Boot detected).
4
+
5
+ ---
6
+
7
+ ## 🛡️ Key Inspection Areas & Rules
8
+
9
+ ### 1. Spring Security & CSRF
10
+ * `TG-CSRF-001`: Prohibit `.csrf().disable()` or `AbstractHttpConfigurer::disable` on state-changing browser routes.
11
+ * `TG-PLATFORM-001`: Avoid `@CrossOrigin(origins = "*")` with `allowCredentials = "true"`.
12
+
13
+ ### 2. JPA & Hibernate SQL Injection
14
+ * `TG-INPUT-002`: Use named parameters (`:param`) or `CriteriaBuilder`. Never concatenate strings into JPQL queries.
15
+ * `TG-DB-004`: Enforce tenant isolation via `@Filter` or explicit where clauses.
16
+
17
+ ### 3. Insecure Deserialization & XML
18
+ * Prohibit `ObjectInputStream.readObject()` on untrusted input without look-ahead verification.
19
+ * Disable external entity resolution (`setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)`).
20
+
21
+ ---
22
+
23
+ ## 🛠️ Safe Patterns Summary
24
+
25
+ ```java
26
+ // Safe JPA Query
27
+ @Query("SELECT u FROM User u WHERE u.id = :id AND u.tenantId = :tenantId")
28
+ Optional<User> findByIdAndTenantId(@Param("id") Long id, @Param("tenantId") String tenantId);
29
+
30
+ // Safe Spring Security Configuration
31
+ @Bean
32
+ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
33
+ http
34
+ .authorizeHttpRequests(auth -> auth
35
+ .requestMatchers("/public/**").permitAll()
36
+ .anyRequest().authenticated()
37
+ );
38
+ return http.build();
39
+ }
40
+ ```
@@ -0,0 +1,25 @@
1
+ # TorusGuard Universal Polyglot Security Matrix
2
+
3
+ > **Loaded When:** Any language or framework is detected. Maps universal security invariants across major programming language ecosystems.
4
+
5
+ ---
6
+
7
+ ## 🛡️ Cross-Language Invariant Mappings
8
+
9
+ | Rule Family | Python | TypeScript / Node.js | Go | Rust | Java / Kotlin | C# / .NET |
10
+ |---|---|---|---|---|---|---|
11
+ | **TG-SEC (Secrets)** | `os.environ["KEY"]` | `process.env.KEY` | `os.Getenv("KEY")` | `std::env::var("KEY")` | `System.getenv("KEY")` | `Environment.GetEnvironmentVariable()` |
12
+ | **TG-DB (SQL Injection)** | `%s` / ORM bound | `$1` / Prisma / Drizzle | `?` / `$1` / GORM `?` | `sqlx::query!` / Diesel | Named parameters `:param` | `@p0` / `FromSqlInterpolated` |
13
+ | **TG-DB-004 (Tenant Scope)** | `.filter(tenant=...)` | `where: { tenantId }` | `.Where("tenant_id = ?", tid)` | `filter(tenant_id.eq(tid))` | `WHERE e.tenantId = :tid` | `.Where(x => x.TenantId == tid)` |
14
+ | **TG-AUTH (Access Control)** | `@login_required` / Depends | Middleware auth / Guards | Middleware handlers | Tower layer / extractors | `@PreAuthorize` / Spring Sec | `[Authorize]` attributes |
15
+ | **TG-CSRF (Request Forgery)** | CSRF Middleware | SameSite / csurf | Gorilla CSRF | Anti-CSRF token middleware | Spring Security CSRF | `[ValidateAntiForgeryToken]` |
16
+ | **TG-DIFF (Bypass Comments)** | No `# nosec` | No `// nosec` | No `/* nosec */` | No `#![allow(unsafe)]` | No `@SuppressWarnings` | No pragma disable |
17
+ | **TG-DIFF (TLS Verification)** | No `verify=False` | No `rejectUnauthorized:false` | No `InsecureSkipVerify: true` | No `danger_accept_invalid_certs`| No `TrustAllStrategy` | No `DangerousAcceptAny...` |
18
+
19
+ ---
20
+
21
+ ## 🚀 Polyglot Hardening Rules of Thumb
22
+
23
+ 1. **Parameterize Everything:** Never concatenate raw user input into SQL, shell commands, LDAP filters, or template strings, regardless of language.
24
+ 2. **Fail Closed on Auth:** Default all endpoints to authenticated; explicitly mark public routes rather than remembering to protect private ones.
25
+ 3. **Strict Bounds:** Keep remediation diffs minimal ($\le 35$ additions, $\le 25$ deletions) to ensure auditability across all codebases.
@@ -0,0 +1,40 @@
1
+ # TorusGuard Skill Reference: Rust Security
2
+
3
+ > **Loaded When:** A project is identified as a Rust application (`Cargo.toml` or `.rs` files detected).
4
+
5
+ ---
6
+
7
+ ## 🛡️ Key Inspection Areas & Rules
8
+
9
+ ### 1. Memory Safety & Unsafe Blocks
10
+ * `TG-INPUT-003`: Audit and restrict `unsafe { ... }` blocks. Must include a `// SAFETY:` rationale comment.
11
+ * Never disable standard borrow checker lints via `#![allow(unsafe_code)]`.
12
+
13
+ ### 2. Database & SQL Queries
14
+ * `TG-INPUT-002`: Use compile-time checked `sqlx::query!` or Diesel query builder methods.
15
+ * `TG-DB-004`: Enforce tenant filtering in queries (`filter(tenant_id.eq(current_tenant_id))`).
16
+
17
+ ### 3. Outbound Requests & TLS
18
+ * `TG-DIFF-001`: Prohibit `danger_accept_invalid_certs(true)` in `reqwest::ClientBuilder`.
19
+ * `TG-SSRF-001`: Enforce IP allowlists before dispatching network calls.
20
+
21
+ ---
22
+
23
+ ## 🛠️ Safe Patterns Summary
24
+
25
+ ```rust
26
+ // Safe sqlx Parameterized Query
27
+ let user = sqlx::query_as!(
28
+ User,
29
+ "SELECT id, email FROM users WHERE id = $1 AND tenant_id = $2",
30
+ user_id,
31
+ current_tenant_id
32
+ )
33
+ .fetch_one(&pool)
34
+ .await?;
35
+
36
+ // Safe reqwest Client (Strict TLS)
37
+ let client = reqwest::Client::builder()
38
+ .timeout(std::time::Duration::from_secs(10))
39
+ .build()?;
40
+ ```