{"success":true,"name":"serve-private-files-through-permission-checks-not-public-lin","description":"Users' documents or images are stored and must be shown back to them","category":"ai-brimind","path":"ai-brimind/serve-private-files-through-permission-checks-not-public-lin/SKILL.md","file":"SKILL.md","content":"---\nname: serve-private-files-through-permission-checks-not-public-lin\ndescription: \"Users' documents or images are stored and must be shown back to them\"\n---\n\n# Serve Private Files Through Permission Checks, Not Public Links\n\n## When to use\nThe app stores files that belong to specific users (invoices, IDs, private photos) and you are writing the code that serves or links to them.\n\n## Example request\nFiles saved in a public folder with the URL kept 'secret' → anyone with the link, forever, can open the file; unlisted is not protected (no auth by URL). Sequential file names like invoice-1041.pdf → changing the number reads other people's invoices; access must be checked per request, per owner (object-level access on files). Cloud bucket set to public because private was inconvenient → the whole storage becomes browsable; buckets stay private and access flows through your rules (default private). Needing to hand the browser a direct file URL → signed URLs give temporary, expiring access without opening the bucket (time-limited signed links).\n\n## Instructions\nAct like a developer who treats a file exactly like a database record: nobody reads it without an authorization check, and a URL is not an authorization check. Store private files in private storage — a bucket or directory that the public internet cannot browse — and never inside the app's public/static folder where the web server hands out anything by path. Serve files through a route that authenticates the user, verifies ownership or permission for that specific file, and only then streams the content or issues the platform's signed URL with a short expiry. Generate storage keys that are non-guessable, but treat that as hygiene, not protection — the per-request permission check is the protection. Set response headers so documents download or display safely rather than execute, and log access to especially sensitive categories (identity documents, financial files). Check whether your storage platform already provides signed URLs and per-object access controls, and prefer those primitives over inventing a scheme. Test by taking a real file link from user A's session and opening it logged out and as user B — both must fail, and links must die after expiry. Only ship once every private file sits behind a named permission check, and explain how this closes the 'anyone with the link' hole that public folders create.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #575\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}