praxis-sec 1.0.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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +170 -0
  3. package/ai-defense/cost-protection.md +292 -0
  4. package/ai-defense/llm-security-checklist.md +324 -0
  5. package/ai-defense/prompt-injection-patterns.js +283 -0
  6. package/ai-defense/system-prompt-armor.md +327 -0
  7. package/checklists/launch-day.md +168 -0
  8. package/cli/agents/abom-generator.js +225 -0
  9. package/cli/agents/agent-attestation-agent.js +318 -0
  10. package/cli/agents/agent-config-scanner.js +787 -0
  11. package/cli/agents/agent-telemetry-agent.js +415 -0
  12. package/cli/agents/agentic-security-agent.js +296 -0
  13. package/cli/agents/agentic-supply-chain-agent.js +463 -0
  14. package/cli/agents/ai-infra-inventory-agent.js +449 -0
  15. package/cli/agents/api-fuzzer.js +345 -0
  16. package/cli/agents/auth-bypass-agent.js +348 -0
  17. package/cli/agents/base-agent.js +280 -0
  18. package/cli/agents/cicd-scanner.js +300 -0
  19. package/cli/agents/config-auditor.js +757 -0
  20. package/cli/agents/deep-analyzer.js +776 -0
  21. package/cli/agents/endpoint-agent-abuse-agent.js +404 -0
  22. package/cli/agents/exception-handler-agent.js +187 -0
  23. package/cli/agents/git-history-scanner.js +169 -0
  24. package/cli/agents/governance-audits.js +138 -0
  25. package/cli/agents/hermes-security-agent.js +536 -0
  26. package/cli/agents/html-reporter.js +1125 -0
  27. package/cli/agents/index.js +147 -0
  28. package/cli/agents/injection-tester.js +502 -0
  29. package/cli/agents/legal-risk-agent.js +328 -0
  30. package/cli/agents/llm-redteam.js +199 -0
  31. package/cli/agents/managed-agent-scanner.js +333 -0
  32. package/cli/agents/mcp-security-agent.js +588 -0
  33. package/cli/agents/memory-poisoning-agent.js +305 -0
  34. package/cli/agents/mobile-scanner.js +231 -0
  35. package/cli/agents/model-file-scanner.js +259 -0
  36. package/cli/agents/orchestrator.js +355 -0
  37. package/cli/agents/pii-compliance-agent.js +301 -0
  38. package/cli/agents/policy-engine.js +229 -0
  39. package/cli/agents/prompt-injection-prober.js +224 -0
  40. package/cli/agents/rag-security-agent.js +204 -0
  41. package/cli/agents/recon-agent.js +207 -0
  42. package/cli/agents/sbom-generator.js +265 -0
  43. package/cli/agents/scoring-engine.js +273 -0
  44. package/cli/agents/ssrf-prober.js +130 -0
  45. package/cli/agents/stateful-watcher.js +238 -0
  46. package/cli/agents/supabase-rls-agent.js +154 -0
  47. package/cli/agents/supply-chain-agent.js +857 -0
  48. package/cli/agents/swarm-orchestrator.js +200 -0
  49. package/cli/agents/verifier-agent.js +303 -0
  50. package/cli/agents/vibe-coding-agent.js +250 -0
  51. package/cli/bin/praxis.js +866 -0
  52. package/cli/commands/abom.js +73 -0
  53. package/cli/commands/agent-fix.js +1245 -0
  54. package/cli/commands/audit.js +1180 -0
  55. package/cli/commands/autofix.js +383 -0
  56. package/cli/commands/baseline.js +193 -0
  57. package/cli/commands/benchmark.js +327 -0
  58. package/cli/commands/checklist.js +223 -0
  59. package/cli/commands/ci.js +403 -0
  60. package/cli/commands/deps.js +516 -0
  61. package/cli/commands/diff.js +200 -0
  62. package/cli/commands/doctor.js +195 -0
  63. package/cli/commands/env-audit.js +349 -0
  64. package/cli/commands/fix.js +218 -0
  65. package/cli/commands/guard.js +396 -0
  66. package/cli/commands/hooks.js +278 -0
  67. package/cli/commands/init.js +514 -0
  68. package/cli/commands/legal.js +158 -0
  69. package/cli/commands/live-advisories.js +241 -0
  70. package/cli/commands/mcp.js +660 -0
  71. package/cli/commands/openclaw.js +386 -0
  72. package/cli/commands/red-team.js +350 -0
  73. package/cli/commands/redteam.js +78 -0
  74. package/cli/commands/remediate.js +797 -0
  75. package/cli/commands/rotate.js +768 -0
  76. package/cli/commands/rules.js +196 -0
  77. package/cli/commands/scan-mcp.js +534 -0
  78. package/cli/commands/scan-skill.js +588 -0
  79. package/cli/commands/scan-standard.js +251 -0
  80. package/cli/commands/scan.js +524 -0
  81. package/cli/commands/score.js +449 -0
  82. package/cli/commands/shell.js +514 -0
  83. package/cli/commands/team-report.js +398 -0
  84. package/cli/commands/undo.js +161 -0
  85. package/cli/commands/update-intel.js +126 -0
  86. package/cli/commands/vibe-check.js +276 -0
  87. package/cli/commands/watch.js +757 -0
  88. package/cli/commands/web.js +63 -0
  89. package/cli/core/ast/guardrail-detector.js +141 -0
  90. package/cli/core/ast/index.js +22 -0
  91. package/cli/core/ast/parser.js +676 -0
  92. package/cli/core/ast/scope-tree.js +287 -0
  93. package/cli/core/ast/taint-tracker.js +158 -0
  94. package/cli/core/branding.js +37 -0
  95. package/cli/core/env.js +38 -0
  96. package/cli/core/errors.js +61 -0
  97. package/cli/core/fs.js +62 -0
  98. package/cli/core/output/compliance.js +90 -0
  99. package/cli/core/output/html-theme.js +158 -0
  100. package/cli/core/output/index.js +57 -0
  101. package/cli/core/output/json.js +48 -0
  102. package/cli/core/output/sarif.js +240 -0
  103. package/cli/core/version.js +67 -0
  104. package/cli/core/web/jobs.js +183 -0
  105. package/cli/core/web/projects.js +146 -0
  106. package/cli/core/web/server.js +439 -0
  107. package/cli/data/atlas-knowledge.json +5640 -0
  108. package/cli/data/eaa-catalog.json +39 -0
  109. package/cli/data/known-mcps.json +26 -0
  110. package/cli/data/probes/prompt-injection-corpus.json +271 -0
  111. package/cli/data/threat-intel.json +85 -0
  112. package/cli/data/threatpacks/latest.json +41 -0
  113. package/cli/hooks/patterns.js +313 -0
  114. package/cli/hooks/post-tool-use.js +140 -0
  115. package/cli/hooks/pre-tool-use.js +186 -0
  116. package/cli/index.js +90 -0
  117. package/cli/providers/llm-provider.js +766 -0
  118. package/cli/utils/autofix-rules.js +74 -0
  119. package/cli/utils/cache-manager.js +310 -0
  120. package/cli/utils/compliance-map.js +191 -0
  121. package/cli/utils/entropy.js +132 -0
  122. package/cli/utils/fix-ledger.js +127 -0
  123. package/cli/utils/hermes-tool-registry.js +252 -0
  124. package/cli/utils/intel/cache.js +61 -0
  125. package/cli/utils/intel/http.js +88 -0
  126. package/cli/utils/intel/index.js +235 -0
  127. package/cli/utils/intel/merge.js +229 -0
  128. package/cli/utils/intel/sources/epss.js +54 -0
  129. package/cli/utils/intel/sources/ghsa.js +81 -0
  130. package/cli/utils/intel/sources/gitguardian.js +40 -0
  131. package/cli/utils/intel/sources/gitleaks.js +101 -0
  132. package/cli/utils/intel/sources/kev.js +38 -0
  133. package/cli/utils/intel/sources/nvd.js +84 -0
  134. package/cli/utils/intel/sources/osv.js +132 -0
  135. package/cli/utils/intel/sources/phylum.js +44 -0
  136. package/cli/utils/intel/sources/snyk.js +46 -0
  137. package/cli/utils/intel/sources/socket.js +69 -0
  138. package/cli/utils/intel/sources/sonatype.js +84 -0
  139. package/cli/utils/intel/sources/threatpack.js +69 -0
  140. package/cli/utils/mcp-trust.js +60 -0
  141. package/cli/utils/output.js +251 -0
  142. package/cli/utils/patterns.js +1130 -0
  143. package/cli/utils/pdf-generator.js +94 -0
  144. package/cli/utils/plugin-loader.js +364 -0
  145. package/cli/utils/rule-import.js +228 -0
  146. package/cli/utils/rule-registry.js +426 -0
  147. package/cli/utils/scan-fingerprint.js +109 -0
  148. package/cli/utils/scan-playbook.js +312 -0
  149. package/cli/utils/score-history.js +119 -0
  150. package/cli/utils/secrets-verifier.js +247 -0
  151. package/cli/utils/security-memory.js +296 -0
  152. package/cli/utils/standards/atlas-knowledge.js +87 -0
  153. package/cli/utils/standards/index.js +127 -0
  154. package/cli/utils/standards/sources/avid.js +45 -0
  155. package/cli/utils/standards/sources/eu-ai-act.js +89 -0
  156. package/cli/utils/standards/sources/google-saif.js +39 -0
  157. package/cli/utils/standards/sources/iso-42001.js +94 -0
  158. package/cli/utils/standards/sources/mitre-atlas.js +54 -0
  159. package/cli/utils/standards/sources/nist-ai-600-1.js +45 -0
  160. package/cli/utils/standards/sources/owasp-llm.js +45 -0
  161. package/cli/utils/standards/sources/owasp-ml.js +45 -0
  162. package/cli/utils/threat-intel.js +265 -0
  163. package/configs/firebase/firestore-rules.txt +215 -0
  164. package/configs/firebase/security-checklist.md +236 -0
  165. package/configs/firebase/storage-rules.txt +206 -0
  166. package/configs/gitignore-template +258 -0
  167. package/configs/nextjs-security-headers.js +220 -0
  168. package/configs/praxisignore-template +50 -0
  169. package/configs/supabase/secure-client.ts +225 -0
  170. package/configs/supabase/security-checklist.md +278 -0
  171. package/docs/THIRD_PARTY_NOTICES.md +26 -0
  172. package/docs/THREAT_INTEL.md +292 -0
  173. package/docs/USAGE.md +1205 -0
  174. package/docs/design/WEB-UI.md +82 -0
  175. package/package.json +71 -0
  176. package/scripts/check-determinism.mjs +119 -0
  177. package/snippets/README.md +122 -0
  178. package/snippets/api-security/api-security-checklist.md +412 -0
  179. package/snippets/api-security/cors-config.ts +322 -0
  180. package/snippets/api-security/input-validation.ts +430 -0
  181. package/snippets/auth/jwt-checklist.md +322 -0
  182. package/snippets/rate-limiting/nextjs-middleware.ts +211 -0
  183. package/snippets/rate-limiting/upstash-ratelimit.ts +229 -0
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `praxis web` — local web UI for driving scans and managing scan projects.
3
+ *
4
+ * Read-only by design: it orchestrates scans and shows results, and deliberately does
5
+ * NOT expose fix application. See docs/design/WEB-UI.md for the threat model.
6
+ */
7
+
8
+ import { createServer, resolveBind, isLoopback } from '../core/web/server.js';
9
+ import { runScanWithOrchestrator, JobQueue } from '../core/web/jobs.js';
10
+ import { listProjects } from '../core/web/projects.js';
11
+ import * as output from '../utils/output.js';
12
+
13
+ export async function webCommand(options = {}) {
14
+ const host = options.host || '127.0.0.1'; // praxis-ignore SSRF_INTERNAL_IP — loopback default; resolveBind() enforces the remote-bind policy
15
+ const port = parseInt(options.port || '7317', 10);
16
+ const allowRemote = Boolean(options.allowRemote);
17
+ const token = options.token || process.env.PRAXIS_WEB_TOKEN || null;
18
+
19
+ const bind = resolveBind(host, { allowRemote, token });
20
+ if (!bind.ok) {
21
+ output.error(bind.error);
22
+ process.exitCode = 1;
23
+ return;
24
+ }
25
+
26
+ const { server, jobs } = createServer({
27
+ host: bind.host,
28
+ port,
29
+ token: bind.remote ? token : null,
30
+ queue: new JobQueue({ runScan: runScanWithOrchestrator }),
31
+ });
32
+
33
+ await new Promise((resolve, reject) => {
34
+ server.once('error', reject);
35
+ server.listen(port, bind.host, resolve);
36
+ });
37
+
38
+ const actual = server.address();
39
+ output.success(`Praxis Web listening on http://${bind.host}:${actual.port}`);
40
+ if (bind.remote) {
41
+ output.warn('REMOTE BIND — this server exposes source code and scan results. Anyone who can reach it, and knows the token, can read them.');
42
+ } else {
43
+ output.info('Loopback only. Use --allow-remote --token <16+ chars> to expose it deliberately.');
44
+ }
45
+
46
+ const registered = listProjects();
47
+ output.info(registered.length
48
+ ? `${registered.length} project(s) already registered.`
49
+ : 'No projects registered yet — add one from the UI, or POST /api/projects.');
50
+
51
+ output.info('This UI is read-only: it cannot apply fixes. Use `praxis fix` for remediation.');
52
+
53
+ const shutdown = () => {
54
+ output.info('\nShutting down…');
55
+ server.close(() => process.exit(0));
56
+ // Do not let a hung SSE connection block exit forever.
57
+ setTimeout(() => process.exit(0), 2000).unref();
58
+ };
59
+ process.on('SIGINT', shutdown);
60
+ process.on('SIGTERM', shutdown);
61
+
62
+ return { server, jobs, isLoopback: isLoopback(bind.host) };
63
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Praxis AI Guardrail & Defense Framework Detector
3
+ * ==================================================
4
+ *
5
+ * Detects active runtime guardrails, structured generation wrappers, and
6
+ * content moderation defenses in AI/LLM and RAG pipelines.
7
+ *
8
+ * When an active guardrail protects an LLM prompt or RAG vector sink,
9
+ * findings are downgraded or marked as mitigated to prevent false positives.
10
+ */
11
+
12
+ // =============================================================================
13
+ // GUARDRAIL SIGNATURES
14
+ // =============================================================================
15
+
16
+ export const GUARDRAIL_FRAMEWORKS = [
17
+ {
18
+ name: 'NeMo Guardrails',
19
+ category: 'input_output_rails',
20
+ importPatterns: [/from\s+nemoguardrails\s+import/i, /import\s+nemoguardrails/i],
21
+ usagePatterns: [/\bLLMRails\s*\(/i, /\bRailsConfig\s*\(/i, /\brails\.generate\s*\(/i],
22
+ },
23
+ {
24
+ name: 'Llama Guard',
25
+ category: 'moderation_classifier',
26
+ importPatterns: [/llama_guard/i, /LlamaGuard/i],
27
+ usagePatterns: [/\bLlamaGuard\s*\(/i, /\brun_llama_guard\s*\(/i, /\bcheck_moderation\s*\(/i],
28
+ },
29
+ {
30
+ name: 'Outlines (Structured Generation)',
31
+ category: 'structured_generation',
32
+ importPatterns: [/import\s+outlines/i, /from\s+outlines\s+import/i],
33
+ usagePatterns: [/\boutlines\.generate\.(?:choice|json|regex|format)\s*\(/i],
34
+ },
35
+ {
36
+ name: 'Instructor / Structured Outputs',
37
+ category: 'structured_output',
38
+ importPatterns: [/import\s+instructor/i, /from\s+instructor\s+import/i],
39
+ usagePatterns: [/\binstructor\.from_openai\s*\(/i, /\bresponse_model\s*=/i, /\bclient\.beta\.chat\.completions\.parse\s*\(/i],
40
+ },
41
+ {
42
+ name: 'LangChain Moderation / Constitutional',
43
+ category: 'pipeline_rails',
44
+ importPatterns: [/OpenAIModerationChain/i, /ConstitutionalChain/i],
45
+ usagePatterns: [/\bOpenAIModerationChain\s*\(/i, /\bConstitutionalChain\s*\(/i],
46
+ },
47
+ {
48
+ name: 'Zod / Pydantic Schema Validation',
49
+ category: 'schema_validation',
50
+ importPatterns: [/from\s+pydantic\s+import/i, /import\s+\{\s*z\s*\}\s+from\s+['"]zod['"]/i, /require\s*\(\s*['"]zod['"]\s*\)/i],
51
+ usagePatterns: [/\bclass\s+\w+\s*\(\s*BaseModel\s*\)/i, /\bz\.object\s*\(/i, /\bsafeParse\s*\(/i, /\bschema\.parse\s*\(/i],
52
+ },
53
+ {
54
+ name: 'DOMPurify / HTML Sanitizer',
55
+ category: 'content_sanitization',
56
+ importPatterns: [/DOMPurify/i, /sanitize-html/i, /import\s+bleach/i],
57
+ usagePatterns: [/\bDOMPurify\.sanitize\s*\(/i, /\bsanitizeHtml\s*\(/i, /\bbleach\.clean\s*\(/i],
58
+ },
59
+ ];
60
+
61
+ export class GuardrailDetector {
62
+ /**
63
+ * Scan code content for active guardrail frameworks.
64
+ *
65
+ * @param {string} code — Source code
66
+ * @returns {object} — { hasGuardrails: boolean, frameworks: string[], defenses: string[] }
67
+ */
68
+ static detect(code = '') {
69
+ if (!code || typeof code !== 'string') {
70
+ return { hasGuardrails: false, frameworks: [], defenses: [] };
71
+ }
72
+
73
+ const detectedFrameworks = [];
74
+ const detectedDefenses = [];
75
+
76
+ for (const fw of GUARDRAIL_FRAMEWORKS) {
77
+ const hasImport = fw.importPatterns.some(p => p.test(code));
78
+ const hasUsage = fw.usagePatterns.some(p => p.test(code));
79
+
80
+ if (hasImport || hasUsage) {
81
+ detectedFrameworks.push(fw.name);
82
+ detectedDefenses.push(fw.category);
83
+ }
84
+ }
85
+
86
+ return {
87
+ hasGuardrails: detectedFrameworks.length > 0,
88
+ frameworks: detectedFrameworks,
89
+ defenses: Array.from(new Set(detectedDefenses)),
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Check if a specific finding sink is protected by a guardrail.
95
+ *
96
+ * @param {object} finding — Finding object
97
+ * @param {string} code — File code content
98
+ * @returns {object} — { isProtected: boolean, guardrail: string|null, reason: string|null }
99
+ */
100
+ static checkProtection(finding, code = '') {
101
+ const analysis = GuardrailDetector.detect(code);
102
+ if (!analysis.hasGuardrails) {
103
+ return { isProtected: false, guardrail: null, reason: null };
104
+ }
105
+
106
+ const findingRule = finding.rule || '';
107
+ const findingCat = finding.category || '';
108
+
109
+ // LLM / Prompt injection findings
110
+ if (findingCat === 'llm' || findingRule.includes('PROMPT') || findingRule.includes('AGENT')) {
111
+ const aiGuard = analysis.frameworks.find(f =>
112
+ f.includes('NeMo') || f.includes('Llama Guard') || f.includes('Outlines') || f.includes('Instructor') || f.includes('LangChain')
113
+ );
114
+ if (aiGuard) {
115
+ return {
116
+ isProtected: true,
117
+ guardrail: aiGuard,
118
+ reason: `Code uses active AI defense framework: ${aiGuard}`,
119
+ };
120
+ }
121
+ }
122
+
123
+ // RAG findings
124
+ if (findingRule.includes('RAG') || findingCat === 'rag') {
125
+ const schemaGuard = analysis.frameworks.find(f =>
126
+ f.includes('Zod') || f.includes('Pydantic') || f.includes('DOMPurify') || f.includes('NeMo')
127
+ );
128
+ if (schemaGuard) {
129
+ return {
130
+ isProtected: true,
131
+ guardrail: schemaGuard,
132
+ reason: `RAG ingestion pipeline is guarded by ${schemaGuard}`,
133
+ };
134
+ }
135
+ }
136
+
137
+ return { isProtected: false, guardrail: null, reason: null };
138
+ }
139
+ }
140
+
141
+ export default GuardrailDetector;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Praxis AST & Dataflow Engine
3
+ * =============================
4
+ *
5
+ * Unified export surface for:
6
+ * - ASTParser (fast JavaScript/TypeScript & Python tokenizer and parser)
7
+ * - ScopeTree (lexical scope tree & symbol resolution)
8
+ * - TaintTracker (source-to-sink dataflow analysis)
9
+ * - GuardrailDetector (AI runtime defense & guardrail detection)
10
+ */
11
+
12
+ export { ASTParser, Tokenizer, TokenType, NodeType } from './parser.js';
13
+ export { ScopeTree, Scope, ScopeType } from './scope-tree.js';
14
+ export { TaintTracker, UNTRUSTED_SOURCES, SANITIZERS } from './taint-tracker.js';
15
+ export { GuardrailDetector, GUARDRAIL_FRAMEWORKS } from './guardrail-detector.js';
16
+
17
+ export default {
18
+ ASTParser: import('./parser.js').then(m => m.ASTParser),
19
+ ScopeTree: import('./scope-tree.js').then(m => m.ScopeTree),
20
+ TaintTracker: import('./taint-tracker.js').then(m => m.TaintTracker),
21
+ GuardrailDetector: import('./guardrail-detector.js').then(m => m.GuardrailDetector),
22
+ };