I started with a familiar security question: how do I expose content from a CMS without exposing too much of the CMS itself?
The first answers were also familiar. Put the API behind a proxy. Restrict its routes. Add rate limits. Add a web application firewall. Review the permissions one more time.
All of these can be useful. But they keep the same assumption: the public website must talk to the content management system at runtime.
I began to wonder whether the safer API was the one that was no longer an API.
A CMS is a workshop, not a shop window
A content management system contains more than published pages. It knows about drafts, internal fields, editorial states, relations, users, plugins, and administration. Even when its public permissions are carefully configured, it remains a large machine connected to the request path of a much simpler website.
For this project, the frontend only needs public content. It doesn’t create records, authenticate readers, or run transactions. Most of the time it asks predictable questions: give me the archive of articles; give me the detail for this item; give me the current navigation.
That changes the problem.
Instead of letting the browser query the CMS, I can let the CMS publish a snapshot. A separate publisher reads only released content, transforms it into a small public contract, and writes static JSON files to object storage. The frontend reads those files through a content delivery network. The CMS stays behind the boundary where editors use it.
The important property is not S3, a CDN, or any particular vendor. It is the direction of travel. Content can move out through a narrow publishing path. An anonymous request cannot move back through it and reach the CMS.
The public contract is deliberately smaller
Static does not automatically mean safe. Anything delivered without authentication must be treated as public, even when the bucket behind it is private.
So the export cannot be a database dump with a nicer extension. Each entity needs an explicit public schema. For example, the archive contains only what a list view needs:
type ArticleArchiveItem = {
id: string;
title: string;
summary: string;
image: PublicImage | null;
};
The detail can add the fields required by the article page:
type ArticleDetail = ArticleArchiveItem & {
bodyHtml: string;
url: string;
};
I prefer constructing these objects field by field. Destructuring away a few known secrets is easier to write, but it fails open: a new internal field can quietly become public. An allowlist fails closed.
function toPublicArticle(record: CmsArticle): ArticleDetail {
return ArticleDetailSchema.parse({
id: record.documentId,
title: record.title,
summary: record.summary,
image: toPublicImage(record.cover),
bodyHtml: sanitize(record.body),
url: record.publicUrl
});
}
Draft state, editorial notes, user data, internal relations, and implementation fields never enter the output object. Runtime validation then checks the adapter’s result before any upload begins.
This makes the static layer more than a cache. It becomes both a security boundary and a contract between the CMS and the frontend. If the internal CMS schema changes, an adapter can absorb that change without forcing the public JSON to change at the same time.
Archives, details, and stable paths
The publisher creates one archive for each editorial entity and one detail file for each released record. Keeping them separate avoids loading every full article just to render a list.
api/
manifest.json
versions/
7f3a.../
articles.json
articles/
article-001.json
article-002.json
events.json
events/
event-001.json
The hash identifies a coherent publication. Files below that version are immutable: if their contents change, their path changes too. This lets them use a long cache lifetime without creating a difficult invalidation problem.
The frontend begins with a small manifest:
{
"version": "7f3a...",
"archives": {
"articles": "versions/7f3a.../articles.json",
"events": "versions/7f3a.../events.json"
}
}
It doesn’t need to know where the CMS lives, what its collection names are, or how its relations are represented.
The manifest is the commit point
Individual static files introduce a less obvious failure mode. An archive might point to a new item before its detail file has arrived. A detail might refer to an image that is still uploading. Every request returns 200, yet the publication is inconsistent.
My current answer is to update the manifest last.
The core of the publisher is intentionally uneventful:
async function publish(snapshot: Snapshot): Promise<void> {
const version = hash(snapshot);
const objects = buildVersionedObjects(version, snapshot);
for (const object of objects) {
await putIfChanged(object.path, object.body, {
cacheControl: "public,max-age=31536000,immutable"
});
}
await verifyObjects(objects);
// The only mutable object, written after the snapshot is complete.
await putJson("api/manifest.json", buildManifest(version, objects), {
cacheControl: "no-cache"
});
}
If an upload fails before the last step, the existing manifest still points to the previous complete version. The unfinished objects are harmless because no reader knows their paths. Old versions can remain available for rollback and be removed later by a separate retention policy.
The local end-to-end test already exercises a useful property: the first run writes the snapshot, while a second run with unchanged content uploads nothing. A publishing system should know the difference between checking and changing.
The full production path is not proven yet. Cache behaviour, deletion, recovery, credentials, and reconciliation still need to be tested in the real environment. A passing local test is evidence, not a security certificate.
Separate identities for content and code
The object store can remain private. The CDN receives read-only access through its own origin identity, while the browser only sees the CDN endpoint.
Writes require a sharper separation. The content publisher should be able to write JSON and media, but it should not be able to replace the JavaScript application. The frontend deployment pipeline needs the inverse boundary.
A simplified policy for the content publisher would be narrow enough to read at a glance:
{
"Effect": "Allow",
"Action": ["s3:PutObject", "s3:GetObject"],
"Resource": "arn:aws:s3:::public-site/api/*"
}
In the real policy I would also separate listing permissions, constrain the bucket and prefix precisely, and use temporary credentials rather than long-lived access keys. The example is deliberately incomplete; its purpose is to show the boundary, not to be copied into production.
The private publisher only needs outbound HTTPS. No inbound route to the CMS is required for public delivery. A persistent queue can retain publication work when object storage is unavailable, while a periodic reconciliation job can compare the expected snapshot with what is actually stored. Events provide speed. Reconciliation covers the events that never arrived.
What this architecture does not solve
It does not make unsafe rich text safe. HTML still needs sanitisation and a restrictive Content Security Policy.
It does not protect members-only content. If a JSON file is delivered publicly, hiding its link in the frontend is irrelevant. Private content needs authorisation enforced before delivery.
It also does not make unpublishing trivial. Removing sensitive content requires a tested path through the publisher, storage, CDN caches, and retained versions. That path deserves the same attention as publication.
Search, forms, authentication, and other write operations may still need dynamic services. The useful boundary is not “static everything”. It is “keep dynamic systems out of the public path unless the feature actually needs them”.
The smaller door
I was initially trying to secure a door between the website and the CMS. The more useful idea was to make that door smaller until only validated, published files could pass through it, in one direction, under an explicit contract.
The CMS remains dynamic where people work. The public site receives a snapshot that is simple enough to inspect, cache, version, and replace.
There is still a publisher to distrust, test, and monitor. But that feels like a better problem than asking every anonymous page view to cross the boundary into the editorial system.