Viewer tokens retain access after dataset switched from private to public
0 reputation · 04 Jan 2024, 06:53 UTC
0 reputation · 04 Jan 2024, 06:53 UTC
When a Sanity dataset is changed from private to public, any existing viewer‑scoped API token instantly gains read access to all documents in that dataset.
This transition occurs without a new token issuance, without an explicit audit‑log entry linking the token to the new visibility state, and without automatic token revocation, leaving administrators uncertain about which credentials now enjoy unrestricted read rights.
The goal is to understand the exposure window and to determine whether any built‑in safeguards can be applied to prevent unintended public access when toggling dataset visibility.
What audit information is available to identify which tokens acquire access after a visibility change? Are there configuration options or operational practices that can enforce token re‑validation or limit the impact of a dataset visibility switch? Is it possible to configure short‑lived tokens or automatic revocation so that a leaked viewer token does not retain indefinite access after a dataset is made public?
31275 reputation · 04 Jan 2024, 07:56 UTC
When a Sanity dataset is switched from private to public, read access to published documents requires no token at all. So the question isn't really which viewer tokens "gain" access — it's that the content itself becomes world-readable to anyone, with or without a credential. Deleting every viewer token after the flip changes nothing, because anonymous requests are already permitted. The exposure window opens the moment the dataset is toggled public and closes only when it's set back to private.
One important caveat: this applies to published documents. Drafts and versioned content remain protected even on public datasets, so confirm which document states actually matter for your content before assuming total exposure.
Sanity's viewer and editor tokens are static, project-scoped credentials created in the management console or via the management API. They do not expire on their own, and Sanity does not revoke or re-validate them when dataset visibility changes. There is no built-in "re-consent" step on a visibility flip — the platform treats visibility as a dataset property, not a token-scoping event.
On plans that include organization or project audit logging, management events such as dataset visibility changes and token creation/deletion are recorded. That lets you reconstruct the exposure picture:
curl -H "Authorization: Bearer $MANAGEMENT_TOKEN" \
https://api.sanity.io/v2021-06-07/projects/$PROJECT_ID/tokensAny token in that list had (at minimum) the access it was created with — but again, the meaningful question after a public flip is who could read the data anonymously, which no token audit can answer. Availability and retention of audit logs depend on your plan tier, so verify what your organization actually captures before relying on it for incident response.
There is no configuration option that forces static viewer tokens to re-validate on a visibility change, and static tokens cannot be given a TTL. The supported pattern for time-limited, revocable read access is third-party tokens: you mint your own signed tokens (typically JWTs with an exp claim) through Sanity's third-party token integration. This gives you per-user, short-lived credentials that expire on your schedule — a leaked token dies with its expiry instead of living forever.
Behavior described here reflects Sanity's well-established model, but confirm against your plan and current docs. A quick check in a test project: create a private dataset with a viewer token, flip it public, and confirm published documents are readable with no Authorization header. Then list tokens via the management API before and after to confirm none are auto-revoked. If you tell us your plan tier, the audit-log guidance above can be narrowed to what your organization actually records.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.