Prismic is a hosted headless CMS. Prismic runs the content backend, and you deploy the website yourself, usually as a front-end app built with a framework such as Next.js. That split decides where to look when a site shows scripts, links or redirects nobody on your team added. There is no theme folder inside Prismic to clean. The problem sits in one of four places: your front-end code, its dependencies and build pipeline, your hosting and tag setup, or the content the app renders.
Where injected code can live on a Prismic site
Because Prismic is software as a service, you do not patch or scan its servers. You control what you deploy and who can reach it. Check these areas in order:
- The front-end repository: layouts, page templates, components, head or document files, middleware and configuration files.
- Dependencies and build scripts: npm packages, lockfiles, install and build scripts, and CI settings.
- Hosting and third-party tags: environment variables, redirect and header rules, and anything loaded through a tag manager or analytics snippet.
- Prismic content: embed fields, rich text and link fields, and any custom field your code prints as raw HTML.
Confirm what visitors actually receive
Start with the symptom, not the code. Open the live page, view the source, and look at the network tab in your browser’s developer tools. Note which script, link or redirect is unexpected and which domain it loads from.
Then repeat the check with a fresh browser profile, on mobile, and arriving from a search result page. Some malicious code only fires for certain visitors, so a clean result from your own laptop proves little. Write down the exact page URLs and the exact snippet you find, because you will search for it in every layer below.
Compare the deployed site with your repository
If your front-end code is in Git, version comparison is your strongest tool. Check the build that is live against the last commit you trust.
- Identify which commit or build your hosting platform deployed.
- Run a diff between that commit and a known-good earlier one, and read every changed file, not only the ones you expect.
- Search the whole repository for the domain or snippet you noted, plus common warning signs: eval, atob, document.write, dangerouslySetInnerHTML, long encoded strings, and unfamiliar script tags.
- Check the commit history for authors, times and messages you do not recognise, and for commits that bypassed review.
- If the live output contains code that is not in the repository at all, the change was made outside Git: in the hosting dashboard, a tag manager or a build step.
Files that deserve extra attention include the root layout, any custom document or head file, middleware, redirect configuration and anything under a public or static folder.
Review dependencies, build scripts and hosting settings
A front-end app pulls in many npm packages, and any of them can run code during install or build. Compare your lockfile against the last trusted version and look for packages you did not add, changed sources, or new install scripts. Remove anything you cannot justify, then reinstall from a clean lockfile.
Next, review the places outside the repository that can change output:
- Environment variables and build commands in your hosting or CI platform.
- Redirect, rewrite and custom header rules.
- Connected Git integrations, deploy hooks and the list of people with deploy access.
- Any tag manager container, since a single added tag can load a script on every page.
The OWASP Top Ten is a useful reference for the wider categories, including vulnerable and outdated components and software and data integrity failures.
Check embeds and content stored in Prismic
Content can carry code too, but only if your app lets it. Prismic documents hold structured fields. Text is normally escaped when your framework renders it. Trouble starts when a template prints a field as raw HTML, or when an editor pastes a snippet into a field that is designed to hold embedded markup.
Open your custom types and look for fields that hold embed code or free-form HTML. Then review the documents that use them, including older ones and drafts. Also read the link fields in rich text for unfamiliar destinations, since hidden spam links are often added there.
Next, find every place your code outputs content unescaped and ask whether it needs to. If you must render embed markup, restrict it to approved providers and sanitise it before output. If you are not sure how a field type behaves, check the Prismic documentation.
Review the repository’s user list in Prismic as well. Remove people who no longer need access and give everyone the lowest role that lets them work. The roles and options available can depend on your plan, so confirm in your repository settings.
Remove the code and rotate credentials
Clean up in a way that cannot be undone by the same flaw. Do not simply delete the visible snippet and move on.
- Take the site into a maintenance state if the code is actively harming visitors, or deploy from a known-good commit.
- Restore the affected files from Git or rewrite them, then rebuild from a clean dependency install.
- Remove the offending content, embeds or links from Prismic documents and publish the corrected versions.
- Rotate every credential that could have been exposed: Prismic access tokens, webhook secrets, hosting and CI tokens, Git provider access, and the passwords of every account that touched any of them.
- Create new tokens, update your environment variables, then revoke the old ones so they stop working.
- Turn on two-step verification for your Prismic, Git and hosting accounts wherever it is offered.
- Re-run the checks from the first section on a fresh browser profile to confirm the code is gone.
Rotation matters because an attacker who holds a token can often return after you clean up. If you find a webhook you did not create, treat it as a sign of wider access and remove it.
Prevent it from coming back
Prevention is mostly about narrowing who and what can change what runs on your pages.
- Require pull requests and reviews for the front-end repository, and protect the main branch.
- Commit your lockfile, install from it in CI, and review dependency changes like code changes.
- Keep access tokens in environment variables, never in the repository or in browser-side code, unless a token is meant to be public.
- Add a Content Security Policy so browsers refuse scripts from domains you have not approved.
- Keep third-party scripts to a short, documented list with an owner for each.
- Set a recurring reminder to review repository users, tokens, webhooks and hosting access.
Frequently asked questions
Can Prismic itself be infected the way a self-hosted theme can?
Prismic hosts the content backend, so you do not manage its server files. What you manage is your front-end app, its dependencies, your hosting, your tokens and your content. Those are the places to inspect.
Will deleting the snippet from the live page fix it?
Rarely. If the snippet comes from a repository file, a dependency, a hosting setting or a Prismic field, it returns on the next deploy or page load. Find the source, fix it there, and rotate credentials.
Should I rotate Prismic tokens even if I only found a bad script?
Yes, if there is any chance a token or account was exposed. Creating new tokens and revoking old ones costs little, while leaving a leaked one active can let the problem return.