A HubSpot CMS site is hosted. HubSpot runs and patches the platform, and there is no plugin repository and no web server for you to maintain. That changes where unwanted code can come from. On HubSpot, injected scripts, hidden links and redirects almost always arrive through something your team controls. That means a user account, a connected app, a custom module or theme file, or a code field somewhere in your settings.
This guide covers where to look, how to compare what is live against a known-good copy, how to remove the code, and how to make a repeat less likely.
Signs that something has been injected
Start by writing down what you or your visitors actually saw. It narrows the search a lot.
- Visitors are sent to another domain, sometimes only on mobile or only when arriving from a search result.
- Links to unrelated topics appear in the footer, in body copy, or hidden with CSS.
- Pop-ups, fake cookie banners or fake update prompts appear that nobody on your team built.
- Your browser’s developer tools show scripts loading from domains you do not recognise.
- Search results show titles or descriptions for your pages that you never wrote.
Open the page, view the source, and search for the unfamiliar domain or snippet. Note whether it appears on every page, one template, or one page only. Sitewide usually points to a theme file, a global template or the site-wide header and footer HTML. A single page points to that page’s own settings or content.
Where injected code can live in HubSpot CMS
Check each of these locations in turn, and do not stop at the first hit.
- Site-wide header and footer HTML. In your website page settings you can add HTML that loads on every page. This is the most common place for a stray script.
- Page-level head and footer HTML. Each page, blog post and landing page has advanced options where custom code can be added. Check the affected pages individually.
- Templates, theme files and modules in the Design Manager. Look at base templates, global partials, custom modules (HTML, JavaScript and CSS fields) and any theme JavaScript file.
- Rich text and HTML modules. Hidden links are often pasted into body content or an HTML module and then hidden with inline styles.
- Tracking code and third-party embeds. Chat widgets, tag managers, ad pixels, form embeds and scheduling tools can all load further scripts. A compromise of an account on one of those services can change what it serves to your visitors.
- Redirect settings. Review your URL redirects for rules pointing to domains you do not own.
If you use a tag manager, remember that the code is not in HubSpot at all. Review the tags and triggers there too.
Compare what is live against a known-good copy
The most reliable way to spot an unexpected change is to compare files against a copy you trust. What is possible depends on how your team works with the site.
If your theme is developed locally, the HubSpot CMS developer documentation describes the HubSpot CLI and the local development workflow. Your source of truth should be a version-controlled project. Fetch the live files from your account into a clean folder, then run an ordinary diff against your repository. Any line you did not write will show up. If your account’s files are synced from a Git repository, check the repository’s commit history for changes from unexpected authors, and look for edits made directly in the account that never went through the repository.
If nobody ever worked from local files, the Design Manager is your main tool. It keeps a version history for templates and modules, so you can open an earlier version and compare it with the current one. Look at when each file last changed and which user made the change. Treat a recent change to a file nobody remembers touching as suspicious.
Also check your account’s user and activity information. What you can see, such as login history or an audit-style activity log, depends on your HubSpot plan, so confirm what is available to you in the HubSpot Knowledge Base. Where it exists, it helps you tie a change to a user or an API key.
Remove the code safely
Work in a deliberate order so you are not cleaning while the door is still open.
- Record before you delete. Save a copy of the malicious snippet and note the file or setting where you found it. You will want it to search for variants.
- Contain access first. Remove unknown users, reset passwords for admins, and revoke connected apps and keys you do not recognise (see the next section). If you clean first and leave access in place, the code can come back.
- Restore rather than patch. For theme files and modules, restore a known-good version or re-upload from your repository instead of hand-editing around the injected lines.
- Clear code fields. Remove the unwanted snippet from site-wide and page-level head and footer HTML, HTML modules and body content.
- Search for variants. Search your templates, modules and content for the domain name, for eval, atob, document.write, and for long encoded strings. Attackers often leave a second copy behind.
- Re-test the live site. Load pages in a private window, on mobile, and when arriving from a search result, since some redirects are conditional. Check the page source again.
If you cannot find the source, publish a fresh copy of the template from your trusted files and compare again. If the problem persists, contact HubSpot support through your account, because they can see platform-side details that you cannot.
Rotate credentials and review connected access
Treat any account that could edit your site as potentially exposed.
- Reset passwords for every user with content or design permissions, and make sure each user has two-factor authentication turned on.
- Remove users who no longer need access, and reduce permissions so only the people who edit code can reach the Design Manager and code fields.
- Review the apps connected to your account, including ones installed from the HubSpot App Marketplace, and remove any you no longer use.
- Regenerate access tokens and keys used by the CLI, private apps or other integrations, and update them wherever they are stored.
- Change credentials on any connected third-party service that serves scripts to your site, such as a tag manager or chat tool.
Do the rotation from a device you trust, since a compromised computer can capture the new passwords as well.
Prevent it from coming back
Prevention comes down to keeping a short list of people who can change code and making every change visible.
- Keep your theme in version control and deploy from it, so any change made directly in the account stands out in a diff.
- Limit custom code to the smallest set of users, and review that list on a schedule.
- Keep an inventory of every third-party script and embed on the site and why it is there. Delete the ones nobody owns.
- Where you load a third-party file you must keep, consider Subresource Integrity so the browser refuses a file that has been altered. This works only for files that do not change on the provider’s side.
- Consider a Content Security Policy to restrict which domains can run scripts. Check how it fits with the scripts HubSpot itself adds before you enforce it.
- Search the live source after each release, looking for unfamiliar domains.
Frequently asked questions
Does HubSpot patch my site if it has been injected with code?
HubSpot looks after the platform, but the code in your theme, modules, embeds and code fields is yours. If an attacker uses a valid user account or connected app to add code, you need to find and remove it yourself.
Can I check for injected code without developer skills?
Yes, to a point. You can view page source, search for unfamiliar domains, and review the header and footer HTML fields and your user list in the account settings. A developer can then compare files against a known-good copy.
Is a malicious redirect always in my theme files?
No. It can come from the site-wide or page-level code fields, a URL redirect rule, or a third-party script that your page loads. Check each of those before assuming the theme is at fault.