Does anyone know if its possible to have PDFs within an app that be delivered through Sanity that can be secured in this way?

5 replies
Last updated: Sep 21, 2020
Hello all,
I am aiming to use Sanity for some web apps that I am building. Part of the requirements of the apps will be to include PDF files within the apps. However these PDFs will contain confidential content that means that the PDFs cannot be accessible through publicly accessible urls.

Does anyone know if its possible to have PDFs within an app that be delivered through Sanity that can be secured in this way?

Thanks as always!
AI Update

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:

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 thread
5 replies
I don’t think you can secure assets in Sanity, you can secure text using a private dataset but as far as I know private datasets do not secure assets (files), but maybe the guys at sanity know something I don’t
user C
- tbh this is what I was presuming - but was just doublechecking. If anyone from Sanity could confirm that would be great.
That’s correct - unfortunately, it’s not possible to secure assets right now. You might be able to achieve it using an external asset source, but I’m afraid I don’t have any examples for you in that case 🙂
That’s correct - unfortunately, it’s not possible to secure assets right now. You might be able to achieve it using an external asset source, but I’m afraid I don’t have any examples for you in that case 🙂
user M
- thanks for the confirmation!

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.

Was this answer helpful?