stacksjs/stacks/stacks-security

Claude Code and agent skill by stacksjs/stacks

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when implementing security in Stacks - password hashing (bcrypt/argon2), app key generation, AES encryption/decryption, hash verification, rehashing detection, security configuration (firewall, rate limiting, IP allowlists), or GDPR data-subject requests (access export, erasure, retention, the processing register). Covers @stacksjs/security, config/security.ts and the GDPR layer in @stacksjs/orm.

Install

npx vskill@latest install stacksjs/stacks/stacks-security

SKILL.md

The same SKILL.md was published earlier as stacksjs/stacks/stacks-security.

Stacks Security

Key Paths

  • Core package: storage/framework/core/security/src/
  • Security config: config/security.ts
  • Hashing config: config/hashing.ts

Source Files

security/src/
├── index.ts # all exports
├── key.ts # generateAppKey()
├── crypt.ts # encrypt/decrypt (AES via APP_KEY)
└── hash.ts # password hashing (bcrypt/argon2)

Scanning a project: buddy security:scan

buddy security:scan (alias buddy audit) checks a project for security problems and exits non-zero on findings at or above --fail-on (default high), so it drops into CI. Five checks, each runnable alone with --only or left out with --skip:

CheckFinds
dependenciesKnown vulnerabilities in the lockfile (bun audit; needs the network, skipped with --offline)
secretsCommitted credentials: private keys, AWS/Stripe/GitHub/Anthropic/OpenAI/Slack/Google/Twilio/SendGrid/npm tokens, database URLs with passwords, secret = "high-entropy value"
codeeval / new Function, shell commands built from strings, SQL built with interpolation, disabled TLS verification, alg: none, innerHTML, Math.random() for tokens, MD5/SHA-1, CORS * with credentials
workflowsGitHub Actions that paste untrusted text into run:, check out a pull request under pull_request_target, echo secrets, or follow a branch
hygieneCommitted .env files with readable secrets (encrypted values are fine), key files, a .gitignore without .env, no lockfile
bash
buddy security:scan # everything, fail on high or worse
buddy security:scan --only dependencies,secrets --fail-on medium
buddy security:scan --json # the report, for tooling
buddy security:scan --show-ignored # what exceptions set aside

A finding that is fine is set aside with a reason, never silently:

  • On the line (or the line above): // security-ignore: code/inner-html the HTML is sanitized by sanitize()
  • In .security-ignore.json: { "ignore": [{ "rule": "code/sql-interpolation", "path": "database/seed.ts", "reason": "ids from rows it just selected", "expires": "2027-06-30" }] }. rule takes code/*; path is a file or a directory ending in /; for an advisory use "reference": "GHSA-…" or the package name. An entry without a reason, or past its expires, is reported and no longer applies.

A check that cannot run (offline, no bun.lock) is listed under "not checked", never reported as clean. Programmatic use: import { runSecurityScan } from '@stacksjs/security/scan'.

App Key Generation

typescript
import { generateAppKey } from '@stacksjs/security'
const key = generateAppKey() // base64: followed by 32 random bytes encoded as base64
// Run via CLI: buddy key:generate

Encryption / Decryption

typescript
import { encrypt, decrypt } from '@stacksjs/security'
const encrypted = await encrypt('sensitive data') // uses APP_KEY
const encrypted = await encrypt('data', 'custom-passphrase')
const decrypted = await decrypt(encrypted)
const decrypted = await decrypt(encrypted, 'custom-passphrase')

Password Hashing

typescript
import { make, makeSync, check, needsRehash, info, detectAlgorithm } from '@stacksjs/security'
// Hash a password
const hash = await make('password123') // bcrypt (default)
const hash = await make('password123', { algorithm: 'argon2' })
const hash = await make('password123', { rounds: 14 }) // bcrypt rounds
// The same hash, answered in place. For a model `set:` hook, so the write it
// belongs to stays in place. It holds the thread for the length of the hash
// (about a quarter of a second for bcrypt at 12 rounds).
const hashedNow = makeSync('password123')
// Verify
const valid = await check('password123', hash) // true/false
// Check if rehash needed (e.g., after changing rounds)
const needs = needsRehash(hash, { rounds: 14 })
// Inspect hash
const hashInfo = info(hash) // { algorithm, options }
const algo = detectAlgorithm(hash) // 'bcrypt' | 'argon2' | 'argon2id' | ...
Aliases
  • hashMake = make
  • hashCheck = check
  • hashNeedsRehash = needsRehash
  • hashInfo = info
  • makeHash = make
  • hashMakeSync = makeHashSync = makeSync
  • verifyHash = check
Algorithm-Specific Functions
typescript
bcryptEncode(value, rounds?) // bcrypt hash
argon2Encode(value, options?) // argon2 hash
check(value, hash) // verifies supported bcrypt/argon2 hashes
base64Encode(value) // base64

HashMakeOptions

typescript
interface HashMakeOptions {
algorithm?: 'bcrypt' | 'argon2' | 'argon2id' | 'argon2i' | 'argon2d'
rounds?: number // bcrypt (default: 12)
memory?: number // argon2 (default: 65536)
time?: number // argon2 (default: 3)
}

config/hashing.ts

typescript
{
driver: 'bcrypt',
bcrypt: { rounds: 12 },
argon2: { memory: 65536, time: 3 }
}

config/security.ts

typescript
{
// Application rate limits and the login lockout are multiplied by this.
// Keep 1 in production; tests raise it (or STACKS_RATE_LIMIT_SCALE).
rateLimit: { scale: 1 },
// Proxies whose forwarding headers name the client (clientAddress()).
// Unset = loopback/private/link-local; [] = trust none.
trustedProxies: ['10.0.0.0/8'],
firewall: {
enabled: true,
countryCodes: [], // block by country
ipAddresses: {
allowlist: [],
blocklist: []
},
rateLimitPerMinute: 500,
useIpReputationLists: true,
useKnownBadInputsRuleSet: true
}
}

Page security headers (config.server.security)

The views server stamps X-Content-Type-Options, Referrer-Policy and X-Frame-Options: SAMEORIGIN (not on embeddable paths) on every page, plus:

  • Strict-Transport-Security: max-age=31536000; includeSubDomains when APP_URL

is https on a real host. Never for localhost, *.localhost, *.test or a loopback IP. hsts: false turns it off; a string replaces the value.

  • Cross-Origin-Opener-Policy: same-origin-allow-popups, which keeps OAuth and

payment popups working (crossOriginOpenerPolicy).

  • Permissions-Policy turning off browsing-topics, usb, serial, hid,

bluetooth and midi, the features no stx composable uses. permissionsPolicy merges features over that; false drops the header.

  • An opt-in page CSP (csp: 'report-only' to observe, then csp: true): a

fresh nonce on every <script>, script-src 'self' 'nonce-...', inline styles allowed, object-src 'none'. csp.directives merge over the defaults; false drops one. Inline on*= attributes are blocked when enforced, so start report-only.

A header the response already carries always wins, and STACKS_SECURITY_HEADERS_DISABLE=true turns the set off behind a proxy that adds its own. The API's STACKS_CSP never reaches a page. Source: core/server/src/security-headers.ts.

Personal data and GDPR

Data-subject requests are driven by model declarations, not by code you write per request: personal: true on an attribute and traits.gdpr on the model (see stacks-models, "Personal data (GDPR)", and docs/guide/gdpr.md).

bash
buddy gdpr:export <id|email> --out file.json # access (Art. 15/20)
buddy gdpr:erase <id|email> --dry-run # then without --dry-run, or --yes
buddy gdpr:prune --dry-run # retention; PruneRetainedDataJob runs daily
buddy gdpr:register && buddy gdpr:register:check
typescript
import { eraseSubject, exportSubjectData, pruneRetainedData } from '@stacksjs/orm'
  • GET /me/data-export (auth bundle, auth middleware, 3/hour) is the

self-service export; the subject is always the caller.

  • Erasure runs in one transaction with its gdpr_requests audit row, writes only

rows it matched to the subject, then revokes tokens and destroys sessions.

  • Erasure of the User row anonymizes rather than deletes: orders, payments and

memberships still point at it. Consent and suppression records are kept by declaration, since honouring an opt-out needs the address.

  • The audit ledger stores counts, never values. Do not log export payloads with

log, which writes to disk in production.

Gotchas

  • Default hashing is bcrypt with 12 rounds - sufficient for most applications
  • needsRehash() compares current hash options against provided options - useful after config changes
  • APP_KEY is used for encrypt()/decrypt() - generate via buddy key:generate
  • APP_KEY format is colon-separated (validated during deployment)
  • Argon2 requires more memory/time but is more resistant to GPU attacks
  • Base64 is encoding, not hashing. Never use base64Encode() for credentials.
  • MD5 and base64 password verification are intentionally absent from the main security API.
  • The firewall config is used by cloud deployment for WAF rules
  • security.waf configures the zig-waf web application firewall on box deploys (Hetzner, ssh):

mode (off | detection | blocking, default detection), paranoiaLevel, thresholds, maxBodyBytes, bypassPaths, reviewed exclusions ({ ruleId, pathPattern?, reason }) and forward (Guardian ingest URL and per-host token, usually from GUARDIAN_INGEST_URL / GUARDIAN_INGEST_TOKEN). It becomes ts-cloud's infrastructure.compute.waf; an explicit compute.waf in config/cloud.ts still wins field by field and the deploy warns about it. Nothing ever switches to blocking by itself: read the detection log first. On AWS deploys the zig-waf-only options are reported, not applied.

  • An app not behind rpx (buddy dev, serverless, a host of your own) can run the same engine in

process: add the waf middleware to a route or group (.middleware('waf')). It is @stacksjs/waf, zig-waf's C ABI through bun:ffi, and reads the same security.waf plus two settings of its own: rules, the SecLang files to load in order (usually an OWASP CRS checkout: crs-setup.conf then rules/*.conf; zig-waf ships none, so it refuses to start without them), and library, the path to zig-waf's shared library (or ZIG_WAF_LIBRARY; it is in lib/ of a zig-waf release or zig-out/lib/ after zig build). Detection mode logs a match and lets the request through; blocking refuses it with the rule's status. dataDir (default: the last rule file's directory, a CRS checkout's rules/) is where .data files resolve, and allowedMethods defaults to CRS's GET HEAD POST OPTIONS plus PUT, PATCH and DELETE, which CRS alone would refuse. At most maxBodyBytes of a body is read; blocking refuses a larger one with 413. In blocking mode a WAF that cannot start answers 503 instead of letting everything through; in detection mode it logs and passes. A request built in-process has no socket and is not inspected. With zig-utils/zig-waf#84 a two-rule set costs about 15 us per request and full CRS about 10 ms for a GET, most of it zig-waf recompiling operators per request (zig-utils/zig-waf#83). A form post costs more, mostly zig-regex backtracking over the body (zig-utils/zig-regex#53); see core/waf/README.md.

  • The firewall rate limit is per-minute per-IP at the WAF (firewall.rateLimitPerMinute)
  • Application rate limits (.rateLimit(), rateLimit(), the login lockout) share the Redis cache when it is configured and count per process otherwise; see stacks-router

Encryption and webhook contracts

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
624
Repository forks
19
7-day trend score
32

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/stacksjs/stacks/stacks-security/badge)](https://verified-skill.com/skills/stacksjs/stacks/stacks-security)

Something wrong with this skill or its page? Tell us.