Skill

nw-security-by-design

Security design principles, STRIDE threat modeling, OWASP Top 10 architectural mitigations, and secure patterns. Load when designing systems or reviewing architecture for security.

From nw
Install
1
Run in your terminal
$
npx claudepluginhub nwave-ai/nwave --plugin nw
Tool Access

This skill uses the workspace's default tool permissions.

Skill Content

Security by Design

OWASP Security Design Principles

Apply these during design -- retrofitting security is 10-100x more expensive.

#PrincipleArchitect Action
1Security by DesignInclude security requirements in architecture documents
2Security by DefaultShip restrictive defaults; require explicit opt-in for relaxed settings
3Defense in DepthLayer controls: WAF + input validation + output encoding + parameterized queries
4Fail SecureDeny access on error; closed-by-default network policies
5Least PrivilegeScoped service accounts; time-limited tokens; minimum permissions
6CompartmentalizeNetwork segmentation; separate databases per trust level
7Separation of DutiesSeparate deployment approval from code authorship
8Economy of MechanismMinimize attack surface; simple, auditable security code
9Complete MediationCheck authorization on every request; no cached auth decisions
10Open DesignUse published, peer-reviewed algorithms; no security-through-obscurity
11Least Common MechanismSeparate admin and user interfaces
12Psychological AcceptabilityMake the secure path the easy path; minimize user friction

STRIDE Threat Modeling

Apply STRIDE to every component in a Data Flow Diagram (DFD). Four questions drive every session:

  1. What are we working on? (system model)
  2. What can go wrong? (threat identification)
  3. What are we going to do about it? (mitigation)
  4. Did we do a good enough job? (review)

STRIDE Reference

ThreatViolated PropertyArchitectural Mitigation
SpoofingAuthenticationMFA, mutual TLS, certificate pinning, OAuth2+PKCE
TamperingIntegrityInput validation, HMAC, parameterized queries, immutable infra
RepudiationNon-repudiationTamper-evident logging (append-only), digital signatures, SIEM
Info DisclosureConfidentialityEncryption at rest+transit, least privilege, generic error messages
Denial of ServiceAvailabilityRate limiting, circuit breakers, auto-scaling, query complexity limits
Elevation of PrivilegeAuthorizationLeast privilege, RBAC/ABAC, signed tokens verified server-side

STRIDE per DFD Element

DFD ElementMost Relevant Threats
External EntitySpoofing
ProcessAll six STRIDE threats
Data StoreTampering, Info Disclosure, Repudiation, DoS
Data FlowTampering, Info Disclosure, DoS
Trust BoundarySpoofing, Tampering, Elevation of Privilege

Risk Response Options

ResponseWhenExample
MitigateProbable and impactful; controls feasibleAdd MFA for spoofing on admin login
EliminateRemove feature/component entirelyRemove unused admin API endpoint
TransferBetter managed by another partyUse managed IdP (Auth0, Cognito)
AcceptLow risk; mitigation cost exceeds impactAccept DoS risk on internal status page

OWASP Top 10 -- Architectural Prevention

Focus on what the architect decides at design time, not implementation details.

A01: Broken Access Control (61% of breaches)

  • Deny by default -- no endpoint open unless explicitly granted
  • Centralized authorization service (OPA, Casbin, Cedar), not scattered checks
  • Resource-level ownership -- queries scoped to authenticated user
  • ABAC over simple RBAC for complex multi-tenant systems
  • CORS with explicit origin allowlists -- never wildcards with credentials

A02/A05: Security Misconfiguration (rose to #2 in 2025)

  • Infrastructure as Code with security scanning (tfsec, checkov) in CI/CD
  • Hardened base images -- minimal containers with security baked in
  • Configuration drift detection with automated alerting
  • Environment parity -- same hardening across dev/staging/prod

A03: Injection (SQL #2 in CWE Top 25 2025)

  • Parameterized queries everywhere -- reject PRs with string concatenation in SQL
  • Treat ALL database-sourced data as potentially tainted (second-order injection)
  • Allowlisting for dynamic query elements (table names, sort columns)
  • Template sandboxing -- user input as DATA, never as template source

A04: Insecure Design (new in 2021)

  • Mandate STRIDE analysis as gate for architecture reviews
  • Abuse cases alongside every user story ("As an attacker, I want to...")
  • State machines with explicit transitions for business logic
  • Rate limiting built into architecture from day one

A06/Supply Chain (expanded in 2025)

  • SCA scanning on every commit (Snyk, Dependabot)
  • SBOM generation as build artifact
  • Private package registry; block direct public pulls in production builds
  • Lock files committed with integrity hash verification

A07: Authentication Failures

  • Centralized IdP (Keycloak, Auth0, Cognito) -- no custom auth per service
  • MFA required for sensitive data access and admin functions
  • Progressive delays on failed attempts (exponential backoff, not permanent lockout)
  • Session ID regeneration on every authentication state change

Secure Architecture Patterns

Zero Trust

Core: "Never trust, always verify" -- no implicit trust from network location.

ComponentImplementation
Identity verificationOAuth2/OIDC for users; mTLS for services
Transport securitymTLS everywhere; service mesh (Istio, Linkerd)
Micro-segmentationNetwork policies limiting service-to-service
Continuous verificationRe-authenticate and re-authorize every request
Least privilege accessScoped tokens; just-in-time access

Input Validation Pipeline

User Input
  -> Validation (allowlist, type, length, format)
    -> Business Logic (parameterized queries, ORM)
      -> Output Encoding (context-aware: HTML, JS, URL, CSS)
        -> Client

Key: input validation is complementary, not primary defense. Output encoding prevents XSS. Parameterized queries prevent SQLi. Validation adds defense in depth.

Secrets Management

PatternImplementation
Centralized vaultHashiCorp Vault, AWS Secrets Manager, Azure Key Vault
Sidecar injectionVault agent injects secrets into pods at runtime
Encrypted in repoSOPS + KMS for GitOps workflows
Pre-commit scanninggitleaks or TruffleHog blocks secrets before they reach git

Rules: never in source code | never in container images | rotate automatically | separate per environment | audit all access.

Required HTTP Security Headers

HeaderValuePurpose
Content-Security-PolicyStrict nonce-basedPrevent XSS
Strict-Transport-Securitymax-age=63072000; includeSubDomains; preloadForce HTTPS
X-Content-Type-OptionsnosniffPrevent MIME sniffing
X-Frame-OptionsDENY or SAMEORIGINPrevent clickjacking
Referrer-Policystrict-origin-when-cross-originControl referrer
Permissions-PolicyFeature-specificLimit browser APIs

Security Testing in CI/CD

TypeTestsPipeline StageTools
SASTSource code vulnerabilitiesEvery commit/PRSemgrep, CodeQL, SonarQube
SCADependency CVEsBuild stageSnyk, Dependabot, Trivy
DASTRunning applicationStagingOWASP ZAP, Burp Suite
SecretsLeaked credentialsPre-commit + CIgitleaks, TruffleHog

Strategy: SAST pre-commit (fast) -> SCA at build -> container scan -> DAST on staging -> block on critical/high findings.

API Security Checklist (OWASP API Top 10)

#ThreatArchitect Decision
API1BOLA (~40% of API attacks)Object-level authorization in service layer, not just routes
API4Unrestricted resource consumptionRate limiting per-object, not just per-endpoint
API5BFLASeparate admin and user API surfaces
API6Sensitive business flow abuseState machine enforcement, idempotency keys
API9Improper inventory managementAPI versioning with sunset policies; deprecate old versions
API10Unsafe API consumptionNever trust third-party API responses; validate and sanitize

GraphQL-Specific

  • Disable introspection in production
  • Set maximum query depth (10 levels) and complexity limits
  • Limit batch size; exclude sensitive operations from batching
  • Field-level authorization in resolvers

Defensive Coding Patterns (Cross-Reference for Crafters)

RiskVulnerable PatternSecure Alternative
SQL Injectionf"SELECT * FROM users WHERE name = '{name}'"Parameterized: cursor.execute("... WHERE name = %s", (name,))
Deserializationpickle.loads(untrusted)json.loads(untrusted) or Pydantic schema validation
Command Injectionos.system(f"cmd {input}")subprocess.run(["cmd", input], shell=False)
SSTITemplate(user_input)env.from_string(trusted).render(data=user_input)
Mass AssignmentUser(**request.json())DTO with explicit fields, server-set for sensitive
TOCTOU RaceRead-check-write in separate stepsAtomic conditional update (UPDATE ... WHERE condition)
Prototype Pollution (JS)Object.assign(target, untrusted)Map, null-prototype objects, strict schema validation
Stats
Parent Repo Stars299
Parent Repo Forks37
Last CommitMar 20, 2026