cosmicstack-labs/security-audit
Comprehensive security audit methodology covering OWASP Top 10, dependency scanning, threat modeling, and vulnerability assessment. Provides actionable guidance for conducting systematic security audits from scope definition to final reporting.
npx skills add https://github.com/cosmicstack-labs/mercury-agent-skills --skill security-audit
A systematic approach to evaluating the security posture of applications, systems, and infrastructure. This skill equips you with the methodology, tooling, and reporting standards needed to conduct professional-grade security audits.
Security is not a single control but layered protections. An audit must evaluate each layer independently and in combination. A failure in one layer should be caught by another.
Every component, user, and process should have the minimum permissions necessary to function. Audits must verify that privilege boundaries are enforced, not just declared.
Design and audit with the assumption that an attacker has already compromised some part of the system. What can they access? What can they pivot to?
Audit procedures must be reproducible. If two auditors run the same methodology against the same target, they should reach consistent conclusions.
Every finding must be backed by reproducible evidence — a screenshot, a log entry, a network capture, or a code path. "Trust me" is not a finding.
A security audit is a snapshot in time. The goal is not just to find bugs but to improve the process so fewer bugs are introduced in the future.
| Level | Name | Description |
|-------|------|-------------|
| L0 | Ad Hoc | No formal audits. Security reviews happen reactively after incidents. |
| L1 | Basic | Manual vulnerability scanning with off-the-shelf tools. No standardized methodology or reporting. |
| L2 | Defined | Formal audit methodology documented. OWASP Top 10 covered. Findings tracked with CVSS scoring. |
| L3 | Integrated | Audits integrated into CI/CD pipeline. SAST/SCA runs on every commit. DAST runs on staging. Dedicated threat modeling sessions. |
| L4 | Proactive | Continuous security validation. Red team exercises. Bug bounty program. Attack surface management automated. Security metrics tracked over time. |
| L5 | Adaptive | Automated remediation for common findings. AI-assisted threat modeling. Self-healing security controls. Audit findings feed back into developer training. |
Target maturity: For most organizations, L3 is the realistic target. L4 and L5 require dedicated security teams and significant investment.
The OWASP Top 10 represents the most critical web application security risks. Every security audit must assess these categories:
/api/users/{id} endpoints that don't verify the requesting user owns that resource..env files, check password storage algorithms.', ", ;, --, /*), test parameterized queries usage in code review.http://169.254.169.254/, http://localhost:9200/).A structured audit follows five phases:
[SCOPE] → [RECON] → [TESTING] → [REPORTING] → [REMEDIATION]
Before any testing begins, define the boundaries:
Deliverable: Scope document signed by both auditor and stakeholder.
Gather information about the target:
Commands:
# Subdomain enumeration
subfinder -d example.com -o subdomains.txt
# Port scanning
nmap -sV -sC -p- -oA nmap_scan example.com
# Directory brute-force
ffuf -u https://example.com/FUZZ -w /usr/share/wordlists/dirb/common.txt
# Secret scanning (git repo)
gitleaks detect --source=./repo --report=gitleaks-report.json
Execute both automated and manual testing:
Test case documentation:
## Test Case: A01-IDOR-001
**Target:** GET /api/orders/123
**Auth:** User A (low privilege)
**Expected:** 403 Forbidden (not your order)
**Actual:** Returns order data for order 456 after changing ID
**Severity:** High (CVSS 7.5)
**Evidence:** [screenshot] [curl_output.txt]
See the Reporting Format section below for the complete template.
Analyzes source code without executing it.
| Tool | Type | Best For |
|------|------|----------|
| Semgrep | Rules-based | Custom rules, multi-language |
| SonarQube | Platform | CI/CD integration, tech debt |
| CodeQL | Query-based | Deep analysis, complex vulns |
| Brakeman | Ruby-only | Rails security |
Example Semgrep rule:
rules:
- id: hardcoded-api-key
patterns:
- pattern-regex: API_KEY\s*=\s*['"][A-Za-z0-9]{20,}['"]
message: "Hardcoded API key detected"
severity: ERROR
languages: [python, javascript, go]
Tests running applications from the outside in.
| Tool | Type | Best For |
|------|------|----------|
| OWASP ZAP | Free | Automated scanning, CI/CD |
| Burp Suite Pro | Commercial | Manual testing, advanced attacks |
| Acunetix | Commercial | Large-scale automated scanning |
ZAP automated scan:
# Docker-based automated scan
docker run -v $(pwd):/zap/wrk/ -t ghcr.io/zaproxy/zaproxy \
zap-full-scan.py \
-t https://staging.example.com \
-r zap-report.html
Identifies known vulnerabilities in third-party dependencies.
| Tool | Type | Best For |
|------|------|----------|
| Trivy | Open source | Containers, repos, filesystems |
| Snyk | Commercial | Developer workflow integration |
| Dependabot | GitHub-native | Automated PRs for fixes |
| OWASP Dependency-Check | Open source | Java/.NET projects |
Trivy usage:
# Scan a filesystem
trivy fs --severity CRITICAL,HIGH ./my-project
# Scan a Docker image
trivy image myapp:latest --format sarif --output trivy-results.sarif
# Scan container with Grype
grype myapp:latest --fail-on high
# Scan Kubernetes manifests with Kube-bench
kube-bench run --targets master,node --check 1.0,2.0
STRIDE categorizes threats by type:
| Threat | Definition | Example | Mitigation |
|--------|------------|---------|------------|
| Spoofing | Impersonating someone/something | Fake login page | Strong authentication, MFA |
| Tampering | Modifying data in transit | Man-in-the-middle | Signatures, TLS, integrity checks |
| Repudiation | Denying an action was performed | "I didn't delete that data" | Audit logs, digital signatures |
| Information Disclosure | Exposing confidential data | SQL injection leaking passwords | Encryption, access controls, input validation |
| Denial of Service | Making system unavailable | DDoS, resource exhaustion | Rate limiting, load balancing, auto-scaling |
| Elevation of Privilege | Gaining unauthorized access | Zero-day exploit chain | Patch management, least privilege |
STRIDE per-component approach:
For each component (API gateway, database, frontend, worker queue), ask: "Can this be spoofed? Tampered? Repudiated? Disclosed? DoSed? Escalated?"
| Factor | Rating (0-10) |
|--------|---------------|
| Damage Potential | How much damage if exploited? |
| Reproducibility | How reliable is the exploit? |
| Exploitability | How easy is it to exploit? |
| Affected Users | How many users are impacted? |
| Discoverability | How easy is the vulnerability to find? |
Score = (D + R + E + A + D) / 5
DREAD is subjective but useful for prioritizing within a single organization. CVSS is preferred for external reporting.
Every audit report should follow this structure:
| ID | Title | Severity | CVSS | Status | Owner |
|----|-------|----------|------|--------|-------|
| AUD-001 | SQL Injection in login | Critical | 9.8 | Open | @dev-team |
| AUD-002 | Missing CSP Header | Medium | 5.3 | Fixed | @sec-team |
| AUD-003 | Hardcoded AWS Key | High | 7.5 | In Progress | @backend |
Each finding includes:
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:HHigh Impact + High Likelihood = CRITICAL (immediate action)
High Impact + Low Likelihood = HIGH (plan for next sprint)
Low Impact + High Likelihood = MEDIUM (fix during maintenance)
Low Impact + Low Likelihood = LOW (accept or monitor)
| Severity | Score Range |
|----------|-------------|
| None | 0.0 |
| Low | 0.1 - 3.9 |
| Medium | 4.0 - 6.9 |
| High | 7.0 - 8.9 |
| Critical | 9.0 - 10.0 |
Example: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
| Component | Value | Meaning |
|-----------|-------|---------|
| AV (Attack Vector) | N | Network (remotely exploitable) |
| AC (Attack Complexity) | L | Low (no special conditions) |
| PR (Privileges Required) | N | None (no auth needed) |
| UI (User Interaction) | N | None (no user action needed) |
| S (Scope) | U | Unchanged (vuln doesn't cross trust boundary) |
| C (Confidentiality) | H | High (all data exposed) |
| I (Integrity) | H | High (all data can be modified) |
| A (Availability) | H | High (system fully unavailable) |
# Calculate CVSS 3.1 base score manually
# Use the official NVD calculator instead: https://nvd.nist.gov/vuln-metrics/cvss/v3-calculator
# But here's the rough priority ordering:
# Critical: Remote, no auth, full compromise → fix within 24h
# High: Needs auth but leads to data breach → fix within 1 week
# Medium: Requires interaction or special conditions → fix within 1 month
# Low: Hard to exploit, limited impact → fix within next release
Automated tools miss business logic flaws, race conditions, authorization bypasses, and complex injection chains. Always pair automated scanning with manual testing.
Attackers don't respect scope boundaries. A vuln in an "out of scope" third-party integration can be a pivot point into the target. Document risks even if you don't test them.
SAST tools generate false positives. Every finding must be manually verified before it enters the report. Reporting a false positive erodes trust.
Bad: "Fix the SQL injection." Good: "Replace string concatenation with parameterized queries in UserRepository.php lines 42-58 using PDO prepared statements."
Finding bugs is reactive. Threat modeling is proactive. Skipping it means you're only finding what scanners can see.
CVSS doesn't account for business context. A CVSS 6.0 finding on a PII endpoint may be more critical to your organization than a CVSS 9.0 on a public information page.
A finding is not resolved until it's verified as fixed. "We fixed it" must be followed by "Show me."
Dropping a 200-page report on the engineering team with no summary, no triage guidance, and no walkthrough leads to findings being ignored or deprioritized.
Without deadlines, critical findings accumulate. Use SLAs: Critical = 24h, High = 1 week, Medium = 1 month, Low = next release.
By the time a vulnerability is found in production, data may already be compromised. Test in staging, CI/CD, and development environments.
Don't assume authentication works. Test for session fixation, missing logout, JWT none-algorithm attacks, and token leakage in URLs/referrers.
Developers often deploy separate staging environments, test APIs, or personal cloud accounts without security review. Audit for shadow IT.
Take cosmicstack-labs/security-audit from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference docker.
Without those the skill loads but fails at the first command.