saas-authorization

Implement workspace isolation, role-based access control, and threat mitigation for multi-tenant SaaS applications.

579|76|Updated Oct 29, 2026
Ready to run
npx skills add https://github.com/phuryn/product-engineering --skill saas-authorization-phuryn
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: saas-authorization
Source: https://github.com/phuryn/product-engineering/tree/main/app-stack/skills/saas-authorization
Command: npx skills add https://github.com/phuryn/product-engineering --skill saas-authorization-phuryn

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building secure multi-tenant SaaS requires making authorization decisions consistently across every route, API endpoint, webhook, and background job—while preventing cross-tenant data leaks, privilege escalation, and common attack vectors. This Skill eliminates ad-hoc permission checks and provides a production-grade authorization model proven across three live products. ## Core Features & Use Cases - Workspace-scoped data access: Every database query and API call routes through three deterministic functions ensuring no member of workspace A can access workspace B's data, even with a direct ID. - Role and permission architecture: Defines the capability matrix mapping actors (member roles, anonymous visitors, API tokens) to actions, with role-based claims never mixed with entitlements. - Threat mitigation framework: Covers 13 threat classes including cross-tenant access, leaked tokens, injection attacks, anonymous identity, webhooks, scheduled jobs, and customer secrets at rest. - Use Case: You're adding sign-in to your SaaS. Use this Skill to establish the workspace model, define roles and permissions in a matrix, implement the three access functions, and prove cross-tenant tests pass before shipping. ## Quick Start Review the model and threat-model references to identify your workspace shape (organization or individual user), then implement the three functions (resolve, requireVisitor, requireWorkspaceAccess) in your codebase and gate every protected route through them.

Frequently Asked Questions about saas-authorization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent a member of one workspace from accessing another workspace's data?▼

Implement `requireWorkspaceAccess(workspaceId, auth, permission)` so every protected route resolves the resource from the URL, finds its owning workspace, then checks membership. Always return the same 404 for both missing and foreign resources so attackers cannot enumerate valid IDs.

Should I use roles or features to enforce billing plan limits?▼

Never mix them. Roles decide who may act; features decide how much they can do. Roles live in your authorization code; entitlements come from the billing provider via the session's verified claims. Lapsed subscriptions then silently remove capability without breaking authorization logic.

How do I handle authorization for anonymous users without accounts?▼

Issue a random, unguessable cookie on the visitor's first action. Store only the hash in the database, never the plaintext. Use `requireVisitor(thingId, cookie)` to prove the same person returned, distinct from member sessions that prove workspace membership.

What is the difference between a cross-tenant test and a denial test?▼

A cross-tenant test proves a member of workspace A holding workspace B's IDs is refused with the same 404 as a missing ID. A denial test must prove the check was actually reached—not just that a 404 was returned—by asserting the HTTP status, error code, and error message together.

Where should I store API token credentials to prevent leaks if the database is compromised?▼

Store tokens as `prefix_<kid>.<secret>`: keep only the `kid` and `HMAC(pepper, owner ‖ secret)` in the database, never the plaintext secret. Compare in constant time, revoke by tombstone, and scope tokens by workspace and action. Generate a unique pepper you never share.

Why does the model say invariants must be database constraints, not application code?▼

Application code checks are vulnerable to race conditions under concurrency. Once-only actions need primary keys; quotas need locked counts and transactions; lifecycle rules need triggers. The database is the only place a guarantee holds when multiple requests run simultaneously.