WordPress · Drupal · Site Maintenance · Technical SEO · Editorial Policy

How to Find and Remove Injected Code on an Adobe Experience Manager Site

Injected code on an Adobe Experience Manager (AEM) site usually shows up as a script you did not add, links hidden in the footer, or a redirect that fires only for some visitors. AEM is Java-based and built from components, OSGi bundles and the dispatcher. That means the hiding places differ from a PHP theme. This guide shows where to look, how to compare against a known-good state, and how to close the gap.

Where injected code hides in AEM

There is no single theme folder to scan. Unwanted code can sit in several layers, and each layer has a different owner.

  • Component and template markup: HTL files and page components under your project’s application folder, especially the header and footer includes.
  • Client libraries: JavaScript and CSS shipped as clientlibs, including minified files that are hard to read by eye.
  • Authored content: text or embed components that accept raw HTML, page properties that add custom includes, and Experience Fragments reused across many pages.
  • Tag management: containers loaded from a third-party tag manager or Adobe’s own tag tooling. Anyone with publishing rights in a container can add a script there without touching AEM at all.
  • Web server and dispatcher configuration: rewrite rules, header settings and cached files that alter responses before they reach the browser.
  • Custom OSGi bundles and servlets: Java code that can write markup into a response or issue a redirect.

Start by deciding which layer the symptom points to. A script that appears on every page suggests a shared template, a clientlib or a tag container. A script on a few pages suggests authored content.

Confirm what visitors actually receive

Before searching code, capture the evidence. Injected content is sometimes served only to first-time visitors, search crawlers or mobile browsers, so a quick look from your own logged-in browser can miss it.

  1. Load the public publish URL in a private window and view the page source. Search for unfamiliar script tags, iframe elements, base64 strings and external domains.
  2. Open the browser’s network panel and list every third-party host the page contacts. Compare it with the hosts you expect.
  3. Request the same URL with a search-engine style user agent and with a referrer from a search results page. Differences between responses are a strong sign of conditional injection.
  4. Fetch the page directly from the publish instance, bypassing the dispatcher cache, and compare it with the cached copy. If only the cached copy is wrong, the problem is in dispatcher configuration or the cache itself.

Save each response. You will need it to prove the cleanup worked.

Compare code against source control

What you can compare depends on how AEM is hosted.

AEM as a Cloud Service. Custom code is deployed through Cloud Manager pipelines from a Git repository, and Adobe applies product updates for you. The application folders that hold your components are built and deployed rather than edited live, so the repository is your source of truth. Diff the deployed project against the repository’s reviewed history, and check the commit log for changes by accounts or on dates nobody can explain. Because product code is Adobe’s responsibility, focus your search on your own project code, authored content and tag containers.

AEM on-premise or Adobe Managed Services. Your team or partner installs service packs and security fixes, so confirm first that you are current. Adobe publishes security bulletins on its security pages, and a missed fix is a plausible entry point. Then compare the running instance with your last known-good build artifact. Export the application content as a package from Package Manager, unpack it, and run a plain file diff against the package your build produced. Anything that differs and has no matching commit deserves scrutiny. On these models, the repository can be changed at runtime through tools such as CRXDE Lite if they are enabled, so a direct edit is possible and must be checked for.

If you have no clean build to compare against, rebuild from the oldest trusted tag in version control and treat that as the baseline.

Review authored content, embeds and tags

Many injections never touch code. They arrive through content that editors are allowed to change.

  • Search page content for raw script, iframe and onerror strings, and for links styled to be invisible, such as off-screen positioning or zero-size text.
  • Open every embed or custom HTML component on high-traffic pages, and every Experience Fragment used in the header and footer.
  • Check page properties and template policies for custom header or footer includes that nobody on the team recognises.
  • Audit your tag manager: list every tag, who published each version, and remove anything without an owner and a documented purpose.
  • Review redirect and vanity URL settings, and any redirect map kept in dispatcher or web server configuration.

Be careful with minified or obfuscated clientlibs. A file you cannot read is a file you cannot approve. Rebuild it from source and replace it rather than trying to hand-edit it.

Remove the code and rotate access

Work in an order that stops reinjection.

  1. Restrict author access to the people doing the cleanup, and take a copy of the affected content and logs for reference.
  2. Remove malicious code at its source. In code, that means a reviewed commit and a fresh pipeline or build. In content, edit or restore the component. In tags, publish a clean container version.
  3. Invalidate the dispatcher cache so stale infected copies stop being served, and purge any CDN in front of the site.
  4. Rotate every credential that could have been used: author and admin accounts, service users, integration tokens, API keys, repository and pipeline access, tag manager accounts, and any secrets stored in OSGi configuration.
  5. Remove accounts and keys for people and vendors who no longer need access.
  6. Re-test with the same captures from the start and confirm the output is clean for each visitor type.

If the cause turns out to be a missed security fix, apply it now rather than only cleaning up. A cleaned site on an unpatched instance gets reinfected.

Prevent a repeat

  • Keep all custom code in version control with required review before merge, and deploy only through your pipeline or build process.
  • Where your hosting allows it, disable direct repository editing on production instances.
  • Follow Adobe’s security bulletins and install fixes promptly if you run AEM yourself.
  • Limit who can add raw HTML, scripts or embeds in authored content, and give tag manager publishing rights to as few people as possible.
  • Add a Content Security Policy so the browser only runs scripts from hosts you approve, and use Subresource Integrity on third-party files you load.
  • Use multi-factor sign-in through your identity provider where your setup supports it, and give each person their own account.
  • Schedule a recurring check that diffs deployed code against the repository and lists third-party hosts contacted by key pages.

Useful references: Adobe’s security bulletins, the Experience Manager documentation, the OWASP Top Ten, and MDN’s page on Subresource Integrity.

Frequently asked questions

Does AEM as a Cloud Service protect me from injected code?

Adobe handles product updates, but your own components, authored content, third-party scripts and tag containers remain your responsibility. Injection through any of those is still possible.

Why does the problem disappear when I check the page myself?

Some injected scripts only run for first-time visitors, certain devices, or visitors arriving from search. Test with a private window, a search-style referrer and different user agents, and compare cached and uncached responses.

Is deleting the bad script enough?

No. If the entry point stays open, the code returns. Find how it got in, whether through an account, a token, a tag container or an unpatched instance, then close that route and rotate credentials.

We use essential cookies to make this site work and remember your preferences. We do not use advertising or analytics cookies. Privacy Policy. Cookie Policy.