backend-api-auth-guardrails
Skill0 starsChanged 3 months agoMITView on GitHub
Use when backend, API, authentication, authorization, session, token, password, webhook, rate limit, audit log, CORS, CSRF, client error response, OIDC multi-RP browser logout, or front-channel logout work is in scope.
In this repository66 other files it gives its agents.
- adb-android-app-opsSkill
- agents-sdkSkill
- api-documentationSkill
- atlasSkill
- browser-useSkill
- bundleSkill
- changelogSkill
- chatgpt-appsSkill
- chrome-devtools-testSkill
- chronicleSkill
- cloudflare-deploySkill
- cloudflare-email-serviceSkill
- cloudflare-one-migrationsSkill
- cloudflare-oneSkill
- cloudflareSkill
- computer-useSkill
- create-planSkill
- database-analysisSkill
- database-data-guardrailsSkill
- debug-memory-leakSkill
- deep-initSkill
- deploySkill
- develop-web-gameSkill
- dev-workflowSkill
- docSkill
- durable-objectsSkill
- explainSkill
- figmaSkill
- firmware-feature-writerSkill
- fix-bugSkill
- fix-lintSkill
- frontend-mobile-uiux-designerSkill
- frontend-ui-guardrailsSkill
- gemini-cliSkill
- grok-x-searchSkill
- hermes-chromeSkill
- image-file-readerSkill
- imagegenSkill
- infra-ops-mobile-guardrailsSkill
- layout-reviewSkill
- localizeSkill
- multimodal-lookerSkill
- openai-docsSkill
- optimizeSkill
- parallel-devSkill
- plan-modeSkill
- playwrightSkill
- project-planningSkill
- qa-testerSkill
- refactorSkill
- review-changesSkill
- review-fix-shipSkill
- rust-programmerSkill
- sandbox-sdkSkill
- screenshotSkill
- security-auditSkill
- security-scanSkill
- security-threat-modelSkill
- source-command-collab-startSkill
- turnstile-spinSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 2 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Prefer backward-compatible changes.
- Very specific: line 13
Prefer RESTful resource naming, HTTP methods, status codes, and versioning.
- Very specific: line 14
Keep payloads minimal. Prefer incremental reads, partial reads, PATCH, or equivalent partial updates over full refetches, page refreshes, …
- Very specific: line 20
Prefer standard auth models: OIDC, OAuth 2.0, JWT, or server-side session.
- Very specific: line 25
Always distinguish authentication from authorization.
- Very specific: line 30
If local password login exists, hash passwords with Argon2id or bcrypt.
- Distinctive: line 39
Use this section when one identity provider serves multiple browser apps on different origins and “sign out everywhere in this browser” is …
- Very specific: line 51
IdP fan-out: when RPs register frontchannel_logout_uri(s), return an HTML intermediate page that loads each allowlisted URI in a hidden …
- Very specific: line 53
sid: put central session id on id_token so RPs can bind local sessions and match front-channel notifications. - Very specific: line 58
Config source: if front-channel URIs live only in env OIDC_CLIENTS_JSON while runtime clients also come from D1, ensure fan-out still sees …
- Very specific: line 78
Use existing X-Request-ID when present.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Backend API Auth Guardrails
This is a domain-specific expansion of the project's AGENTS.md (or equivalent agent rules). It may add backend, API, and auth requirements, but it must never weaken AGENTS.md, SECURITY, secrets handling, input validation, production safety, or destructive-command restrictions.
API Contracts
- Prefer backward-compatible changes; do not break public API contracts without approval or versioning.
- Prefer
RESTfulresource naming, HTTP methods, status codes, and versioning. If deviating fromRESTful, explain the trade-off. - Keep payloads minimal. Prefer incremental reads, partial reads,
PATCH, or equivalent partial updates over full refetches, page refreshes, or whole-resource overwrites. - Validate external input before use, including type, range, state, and authorization.
- Query capabilities such as
pagination,filter,sort, andsearchmust use explicit allowlists and reasonable limits.
Authentication And Authorization
- Prefer standard auth models:
OIDC,OAuth 2.0,JWT, orserver-side session. Do not invent account verification, token, session, or signature protocols. - Web defaults: use
OIDClogin, create a backendserver-side session, and maintain login withHttpOnly Secure SameSitecookies. - Cloudflare session state: prefer
Durable ObjectsorRediswhen strong consistency or immediate revoke is required; useKVonly when eventual consistency is acceptable. - Mobile defaults: use
OIDC Authorization Code + PKCEwith short-lived access tokens and rotating refresh tokens. - Token-based auth must validate issuer, audience, expiry, rotation, revoke/logout, and permission-change refresh or revalidation behavior.
- Always distinguish
authenticationfromauthorization; protected resources aredeny by default. - Bearer token APIs must validate
iss,aud,exp, and checkscope,role, orpermissionexplicitly.
Passwords, Sessions, And Browser Auth
- If local password login exists, hash passwords with
Argon2idorbcrypt; never store plaintext, reversible encryption, or custom hashes. - Email/phone identity or recovery channels need verification plus short-lived, one-time-use verification mechanisms.
password reset, recovery, disable/suspend/delete/restore, and key account-data changes must define permission boundaries, expiry, replay protection, rate limits, retention, and audit trail.- Password, email, role, or permission changes must handle existing sessions, refresh tokens, and remember-me tokens with revoke or re-auth requirements.
- Browser-based auth should not store sensitive tokens in
localStorage. - Cookie auth must handle
HttpOnly,Secure,SameSite, andCSRF; cross-origin access must use an explicitCORS allowlist.
OIDC Multi-RP Browser Logout (Front-Channel)
Use this section when one identity provider serves multiple browser apps on different origins and “sign out everywhere in this browser” is required.
When to use / when not to use
- Use for multi-subdomain web products that share OIDC SSO but keep independent local sessions (cookies or SPA tokens per origin).
- Do not use as a substitute for all-device logout (that needs account-wide session/refresh revoke + product UX).
- Do not assume “RP-initiated logout” alone clears other RPs: browser same-origin policy blocks clearing foreign cookies.
Correct model
- RP logout path: clear local session first, then top-level navigate to IdP
end_session//oauth/logoutwithclient_id, allowlistedpost_logout_redirect_uri, andid_token_hintwhen available. - IdP revoke gate: bare cross-site GET may clear only the IdP SSO cookie; server session revoke typically needs POST (CSRF-safe) or GET with
id_token_hintbound to the current session subject. - IdP fan-out: when RPs register
frontchannel_logout_uri(s), return an HTML intermediate page that loads each allowlisted URI in a hidden iframe (iss+ optionalsid), then redirect topost_logout_redirect_uri. - RP front-channel endpoint: e.g.
GET /auth/frontchannel-logout?iss=…&sid=…— verifyissexactly, clear this origin’s cookies/tokens,Cache-Control: no-store, allow framing only from the IdP (Content-Security-Policy: frame-ancestors <issuer>). Do not redirect back to the IdP (loop risk). sid: put central session id onid_tokenso RPs can bind local sessions and match front-channel notifications.
Pitfalls (easy to get wrong)
- CSP: global
default-src 'self'blocks cross-origin RP iframes. Logout HTML must allowframe-srcfor allowlisted RP origins (page-specific CSP and/or preserve response CSP over global security headers). - Config source: if front-channel URIs live only in env
OIDC_CLIENTS_JSONwhile runtime clients also come from D1, ensure fan-out still sees every registered URI (env merge or D1 column). - Deploy order: ship RP front-channel endpoints before or with IdP fan-out; missing endpoints just 404 and leave that origin signed in.
- Consumer serde: IdP JSON may return
"profile": null.#[serde(default)]handles missing fields, not null — use null-as-default orOptionor consumers will 5xx on login callbacks for new accounts. - Email gates: some products require verified email for shared-auth login; unverified E2E accounts pass central login but fail RP callback with product-specific errors.
- Test hygiene: cookie assertions must use exact cookie names (e.g.
sessionmust not matchapp_page_sessionvia substring).
Minimal verification
- Discovery advertises front-channel support when implemented.
- Logout HTML lists only allowlisted iframe targets.
- Wrong
isson RP front-channel → 4xx without clearing unrelated sessions whensidis bound. - Real browser: login A + B → logout A → refresh B is signed out; silent SSO does not re-auth without central session.
Abuse, Webhooks, And Errors
login,signup,password reset,OTP,verification resend, andtoken refreshendpoints need rate limiting, cooldowns, retry limits, and replay protection.- Webhooks and async event sources must verify signatures, check timestamp/replay, and use idempotent consumers.
- Security-sensitive operations such as permission changes, failed login, password reset, key account-data changes, and token revoke require
audit log. audit logand normal logs must not record passwords, tokens, OTPs, or other sensitive secrets.- Client errors must be safe and include
error,code, andtrace_id. - Use existing
X-Request-IDwhen present; otherwise generate UUID v4. Include trace ID in logs and error responses. Production logs should be JSON.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

