Does anyone know if its possible to have PDFs within an app that be delivered through Sanity that can be secured in this way?
Good news and important information here! By default, assets in Sanity (including PDFs) are publicly accessible via their URLs, even in private datasets. This is true regardless of your dataset's access control settings - while your document data can be secured, the asset files themselves are served through Sanity's CDN with publicly accessible URLs.
However, you have a few options to secure your PDFs:
1. Use Signed URLs with Sanity Functions (Recommended)
The most secure approach is to not expose the asset URLs directly to your frontend. Instead:
- Store your PDF files in Sanity as normal file assets
- Create a Sanity Function that checks user permissions/authentication
- Have the Function generate temporary signed URLs or proxy the file download
- Your app requests PDFs through this Function, which validates access before serving
This way, the actual Sanity asset URLs remain hidden in your backend code, and you control who can access them.
2. Store Files in External Secure Storage
For highly sensitive content, you might want to:
- Store PDFs in a service designed for private file storage (AWS S3 with signed URLs, Azure Blob Storage, etc.)
- Store only the file reference/ID in Sanity
- Handle authentication and file serving through your own backend
This gives you complete control over access but adds infrastructure complexity.
3. Security Through Obscurity (Limited Protection)
Sanity asset URLs are auto-generated and difficult to guess, providing some "security through obscurity." However, this is not true security - anyone with the URL can access the file, and URLs can be shared or leaked.
Important Considerations
The Sanity documentation explicitly states: "Usually the autogenerated URL of the asset provides enough security through obscurity – but the file itself is publicly accessible, even in private datasets."
For truly confidential content, you'll need to implement additional security layers beyond Sanity's built-in asset storage. The Sanity Functions approach gives you the best balance of convenience and security while keeping your content workflow in Sanity.
Show original thread5 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.