Skip to content
<Notes of dev/>

Would you know if your website was hacked?

21 min read

An owl postman hands a red-sealed letter to a shocked squirrel outside the shop, whose window is covered in cherry and dice posters nobody in the shop put up.

How Google Search Console and Bing Webmaster Tools flag hacks and stray pages, where they stay silent, and what to check on a headless site.

Part 3 of 4 in the "Are you sure your website is safe?" series

TL;DR

Google Search Console and Bing Webmaster Tools report hacked content, spam penalties, unknown owners and pages you never meant to publish. They only report after a crawl, so treat them as a backstop and add a few checks of your own each month. They also show a headless site's indexing problems, such as duplicate URLs and renamed slugs that return 404.

What search consoles report

A hacked page can look normal to its owner. Cloaked spam shows you a clean page or a 404 and shows the search crawler something else. So the search engine often sees the problem first, and it tells you in a webmaster console: Google Search Console or Bing Webmaster Tools.

Think of the two consoles as smoke alarms on the ceiling. An alarm sounds only after smoke reaches it, and it helps only if someone hears it. Both limits get a fix further down.

The analogy has one limit. A smoke alarm and your own nose sense the same smoke. With cloaking, the console and your browser see different pages, and the console is the one that sees the spam.

Security Issues and Manual Actions in Search Console

Search Console has two safety reports. The Security Issues report covers hacked content, malware and unwanted software, and social engineering (pages that trick visitors into installing something or handing over data).

Once the site is clean, you click Request Review, and Google emails owners when it receives the request and again when it finishes. It also warns that "most reconsideration reviews can take several days or weeks" (Security Issues report).

The Manual Actions report covers spam. A manual action is issued "when a human reviewer at Google has determined that pages on the site are not compliant with Google's spam policies", and then "some or all of that site will not be shown in Google search results" (Manual Actions report). You hear about it in the report and in the Search Console message centre.

Google's spam policies count hacked content as spam, so a hack can surface in either report.

What Bing Webmaster Tools adds

Bing's rules now reach into AI answers. The Bing Webmaster Guidelines say cloaking, malicious behaviour and "Prompt Injection and AI Manipulation" can lead to "reduced ranking, suppressed grounding visibility, or delisting from the Bing index" (Bing Webmaster Guidelines).

Grounding — when an AI assistant such as Copilot reads a web page and uses it as a cited source for its answer.

So a hacked page that hides instructions for AI agents can cost you Bing rankings and Copilot citations at once. Bing has also sent malware alerts through its message centre (Bing's 2013 announcement).

Importing a site from Search Console skips Bing's own verification step. The example in this post is a small Next.js site on a headless CMS (content management system). When that site was imported, Bing pulled in both sitemaps and crawled them the same day.

Unknown owners are a warning sign

An owner you never added is one of the clearest signals either console gives. Google says it directly: "If you've found an owner that you don't recognize, you might have been hacked" (Manage users and owners).

Google's hack-cleanup guide treats a notice that "someone you don't know has verified your site" as a strong sign of a hack, and its first step is removing unknown owners (Fix the Japanese keyword hack).

You will usually hear about it. "Whenever a new owner is added to your property, Search Console notifies all existing verified owners of the change" (I don't recognize this new owner). Treat that notice as urgent, and still open the owner list in both consoles now and then.

The squirrel walks in carrying a folded cloth and finds the ferret lounging in the chair behind the shop counter, grinning.
An owner you never added in Search Console is a red flag.

Delete the verification tokens too

Removing an unknown owner takes two steps. Google says you must also "Delete all verification tokens for this user", because "if you do not delete these tokens, the removed owner will be able to re-verify ownership" (Manage users and owners). A token is whatever proved ownership: an HTML file at the site root, a meta tag, or a DNS (Domain Name System) record.

On a headless Next.js site, check the public/ folder for stray google*.html files, the root layout's metadata.verification field, and the TXT records at your registrar.

Verify ownership with DNS, and keep the record

How you verify decides how easily someone can remove you. A Domain property in Search Console accepts "DNS record verification only", and it covers every subdomain and protocol, with and without www (Add a property).

An HTML file or meta tag lives on the site. "Removing this verification file from your site will cause you to lose verification for the site" (Verify your site ownership), and anyone with access to the deployed site can remove it.

Verification is never finished. Search Console "periodically checks if your verification token is still present and valid", and once the token is gone your permissions "will expire after a certain grace period". Google's instruction is plain: "To stay verified, don't remove the DNS record from your provider, even after verification succeeds."

At a registrar such as GoDaddy, the verification is a TXT record at @. When you add SPF (Sender Policy Framework, the email record from Part 1) later, add it as a separate TXT record and leave the verification record alone. The host @ then holds two TXT records:

  • google-site-verification=<your-token> for Search Console
  • v=spf1 -all for SPF

Then turn on 2FA (two-factor authentication) for the registrar and for every Google and Microsoft account that owns a console property. With DNS verification, the registrar login decides who stays an owner.

Route console mail to a watched inbox

Console messages go to the people on the property. If the only owner is an agency account or a former employee, every warning lands in an inbox nobody reads.

  • Add a shared, monitored address (a team alias, not one person) as an owner in both consoles.
  • Review each user's email preferences in Search Console.

How SEO spam reaches a headless site

SEO — search engine optimization, the work of helping search engines find, read and rank your pages. SEO spam abuses a site to rank someone else's pages.

The hacks the consoles look for

Google's spam policies list 16 behaviours (Google spam policies). Three matter most when your site is the victim:

  • Hacked content — "Any content placed on a site without permission, due to vulnerabilities in a site's security".
  • Cloaking — showing search engines different content from what visitors see.
  • Site reputation abuse — third-party content published "mainly because of that host's already-established ranking signals". Google applies it "regardless of whether there is first-party involvement or oversight" (Google's November 2024 update), so approving the content yourself does not make it safe.

The best-known example is the Japanese keyword hack. It creates auto-generated Japanese pages in random directories and cloaks them, so the owner sees a 404 while Googlebot sees spam (Fix the Japanese keyword hack).

Entry points on a site with no PHP

A headless site has no plugin folder or writable server for an attacker to drop files into. Three other entry points stay open.

  1. A stolen CMS management token. A management token can create and publish entries through the API (application programming interface). Your own pipeline then does the rest: the publish webhook refreshes the page and the sitemap lists it. Part 2 covers how these tokens end up in public JavaScript.
  2. A stolen editor account. Same result, through the CMS dashboard.
  3. A compromised dependency. A malicious package version can inject links or scripts into every page at build time. Part 2 covers the install delay that blocks most of these.

Spam published with a stolen token or editor account goes through the normal publishing path. So it looks like ordinary content, and no check on the repository sees it.

Where the console alarm falls short

Back to the smoke alarm. The consoles share its delay, and they have two other gaps.

  • They report after a crawl. Nothing appears until a crawler visits and the report refreshes. On that site, the Pages report was six days old while the URL Inspection data was already current.
  • Removal may come with no alert. An attacker who can delete your verification file can remove you as an owner. Sucuri reported in 2015 that an owner removed this way gets no notice, and Google's current help pages do not say otherwise (Sucuri, 2015). DNS verification makes this harder, because removing you then needs the registrar login.
  • The tools are mostly read-only. On that site, the URL Inspection API only read status, 10 URLs per batch. Request indexing exists only in the web interface.

A slow alarm still earns its place, because the crawler's view and Google's human reviews are nowhere in your repository. You just need your own checks in between.

In practice: your own checks between console reports

Opening a suspect URL in your browser proves little, because cloaking can serve you a 404 while Googlebot gets spam. Search results show what Googlebot fetched, so search instead.

Attackers do the same. OWASP (the Open Worldwide Application Security Project) calls it "Google hacking or Dorking", and AI tools such as DorkGPT now write the queries (OWASP search engine reconnaissance). Run the same searches first: site:example.com plus common spam words (in Japanese too), and site:example.com filetype:pdf.

Then watch the sitemap, where injected pages show up as URLs you never published. Count the entries and compare with the published count in your CMS:

bash
curl -s https://www.example.com/sitemap.xml | grep -c "<loc>"

Why robots.txt does not hide pages

Google says robots.txt "is not a mechanism for keeping a web page out of Google", and "a page that's disallowed in robots.txt can still be indexed if linked to from other sites" (Introduction to robots.txt). It is a request, and "it's up to the crawler to obey them".

A Disallow line also stops noindex from working: "For the noindex rule to be effective, the page or resource must not be blocked by a robots.txt file" (Block indexing with noindex). The crawler has to fetch the page to read the noindex. And robots.txt is public, so lines such as Disallow: /drafts/ and Disallow: /internal-pricing/ tell every visitor where the interesting pages are.

The ferret ducks under a red velvet rope with a stop-hand sign and reaches for a stack of prints while the squirrel watches from the counter.
robots.txt asks crawlers to stay out. It locks nothing.

Use noindex, headers and authentication instead

Each tool has one job:

  • noindex meta tag — for HTML pages that may stay reachable but should not appear in results.
  • X-Robots-Tag: noindex header — the same rule for files with no HTML head, such as PDF (Portable Document Format) files.
  • Authentication — the only option that keeps people and bots out.

In Next.js, the header goes in next.config.ts. Keep downloadable files in one folder so a single rule covers them:

next.config.ts(typescript)
async headers() {
  return [
    {
      source: '/downloads/:path*',
      headers: [{ key: 'X-Robots-Tag', value: 'noindex' }],
    },
  ];
},

Removals last about six months

The Search Console Removals tool hides a URL fast, but "a successful request lasts only about six months" (Removals tool). For a permanent fix you delete the page (returning 404 or 410), put it behind a password, or add noindex.

Preview and staging hosts

Vercel adds "an X-Robots-Tag: noindex HTTP response header to every Preview Deployment automatically" (Vercel preview indexing). The exception is a custom domain assigned to a non-production branch. So staging.example.com on a develop branch is open to indexing unless you add the header yourself. Check it:

bash
curl -sI https://staging.example.com | grep -i x-robots-tag

No output means no noindex. Better still, put staging behind Vercel Deployment Protection or any login, because a header only stops search engines.

Indexing problems a headless site creates itself

All four cases happened on that site. None of them showed up in the build pipeline or in the CMS. Search Console data or response headers revealed each one.

Duplicate post URLs with self-canonicals

Posts lived in a CMS folder called posts/ but published at the site root. A catch-all route also served /posts/{slug} with status 200 and a canonical tag pointing at itself (the canonical is the URL a page declares as its main address). So every post existed at two URLs, both claiming to be the main one. Only about 3 of 17 posts were indexed.

The fix is a permanent redirect. The guard keeps the CMS visual editor working, because it loads /posts/{slug} with a _storyblok query parameter:

next.config.ts(typescript)
async redirects() {
  return [
    {
      source: '/posts/:slug',
      missing: [{ type: 'query', key: '_storyblok' }],
      destination: '/:slug',
      permanent: true,
    },
  ];
},

permanent: true sends a 308. After this fix and the ones below, 19 of 20 sitemap URLs were indexed.

An owl holds up two identical sailboat catalogue cards above a single sailboat book while the squirrel points at the book.
Two URLs that both claim canonical split one post in two.

Renamed slugs need 301 redirects

Changing a slug in the CMS leaves no redirect behind. The old URL returns a 404, or for a while the host may still serve the old page at 200 with a self-canonical. Seven renamed posts on that site needed 301s, from both /{old} and /posts/{old}. One was only found weeks later, in the Search Console "Not found (404)" list.

next.config.ts(typescript)
{ source: '/old-slug', destination: '/new-slug', statusCode: 301 },
{ source: '/posts/old-slug', destination: '/new-slug', statusCode: 301 },

Tag archives crowding out posts

Google had indexed 28 tag pages and only about 4 content pages. The tags drew 5 impressions in 90 days. They were set to noindex, follow and removed from the sitemap. follow keeps crawlers moving through the links on the page:

src/app/tags/[tag]/page.tsx(typescript)
export const metadata = {
  robots: { index: false, follow: true },
};

A sitemap frozen at the reserved path

The sitemap was an ISR route handler at /sitemap.xml, a path Next.js reserves for its own metadata files.

ISR — Incremental Static Regeneration, a Next.js feature that rebuilds a cached page in the background after a set time or on demand.

On Vercel that path was served as a static file, so new posts never reached the sitemap for two months. Comparing its response headers with those of robots.txt gave it away. The fix serves the sitemap from /xml-sitemap and rewrites /sitemap.xml to it. If a publish webhook revalidates the sitemap (as in How to set up Storyblok with Next.js), point it at that path.

When not to expect a traffic jump

These fixes protect the site and clean up the index, and that is all. After all of them, that site had 110 impressions and 3 clicks in 28 days, at an average position of 7.3. Content and links were the bottleneck. Fix duplicates and leaks because they are cheap, then spend the real effort on writing.

Push changes: IndexNow for Bing, Request indexing for Google

With some engines you can skip the crawl wait.

IndexNow — a protocol that lets a site notify search engines the moment a URL is added, updated or deleted.

You prove ownership with a key file hosted on your site, and "you can submit up to 10,000 URLs per post". Submitted URLs are shared with all participating engines (Bing, Yandex, Naver, Seznam and Yep). Google does not participate (IndexNow documentation).

Bing's guidelines recommend it, and it helps after a hack too: submit the removed spam URLs so Bing learns they are gone.

On that site, every publish pings IndexNow with the page URL and the sitemap, from production only so preview builds never announce themselves:

bash
curl -X POST https://api.indexnow.org/indexnow \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{"host":"www.example.com","key":"<your-key>","keyLocation":"https://www.example.com/<your-key>.txt","urlList":["https://www.example.com/new-post","https://www.example.com/sitemap.xml"]}'

For Google there is no push. Keep the sitemap fresh and use Request indexing for pages that matter. It only asks. One post was still "URL is unknown to Google" a few hours after a manual request.

Search consoles and indexing

Six practices here are core. The rest (IndexNow, sitemap counts, tag pages) is useful hardening.

Verify with DNS and keep the TXT record

  • Do — use a Domain property and keep its TXT record for good.
  • Don't — rely only on an HTML file or meta tag.
  • If you skip it — anyone who can change the site can remove you, possibly without any notice, and a deleted record ends your access after a grace period.

Read alerts and the owner list

  • Do — route console mail to a watched inbox and delete an unknown owner's tokens.
  • Don't — leave an agency or a former employee as the only owner.
  • If you skip it — hacks and manual actions go unseen, and a removed owner can verify again.

Turn on 2FA for every account that controls the site

  • Do — protect the code host, deploy host, CMS, registrar, and Google and Microsoft accounts.
  • Don't — leave any of them on a password alone.
  • If you skip it — one stolen password undoes every fix in this post.

Use noindex or a login for private pages

  • Do — send noindex on pages crawlers can fetch, and require a login for anything private.
  • Don't — rely on robots.txt or Removals.
  • If you skip it — the URL can still be indexed from links, and a removal lapses after about six months.

Protect preview and staging hosts

  • Do — put staging behind a login, or at least add noindex to custom-domain previews.
  • Don't — assume the automatic header covers a custom domain.
  • If you skip it — that host is open to indexing like any public site.

Redirect renamed slugs and remove duplicate URLs

  • Do — add a 301 for every renamed slug and send duplicate paths to one URL.
  • Don't — rename in the CMS and move on.
  • If you skip it — old links return 404, and duplicates can keep most posts out of the index (about 3 of 17 on that site).

What to check every month

  • Do you recognise every verified owner in both consoles, and is anything new in Security Issues or Manual Actions?
  • Is the DNS verification record still in place?
  • Does a site: search for spam terms, or for filetype:pdf, return pages you never published?
  • Did the sitemap URL count change more than your publishing explains?
  • Does every preview and staging host ask for a login, or at least return X-Robots-Tag: noindex?
  • Did any slug change, does the old URL return a 301, and is the "Not found (404)" list free of old posts?
  • Are tag or utility pages filling the indexed list in place of content?

A search console is the only place you see your site the way a crawler and a human reviewer see it. Kept clean and read monthly, it can show a hack, a renamed page that now returns 404, or tag pages crowding out your posts while the problem is still small. Left unread, the first sign may be a manual action that has already taken pages out of results.

Next up: Should you block AI crawlers?


The "Are you sure your website is safe?" series: Part 1 | Part 2