Skip to content

integrity/brand-impersonation loses a signal without inter-element whitespace #696

Closed

Description

@deniskern

Summary

Removing one inter-element space suppresses the brand-impersonation signal and downgrades a correlated fake-auth-overlay finding from fail to info. Both fixtures contain the same full-viewport auth iframe and the same off-brand “Sign in with Google” link.

Reproduction scope. Source-level regression test against the unmodified v0.0.108 tag, commit c456496, using the actual parsePage and rule implementations. This is not a published CLI end-to-end replay. Install scripts were disabled; no outbound requests are made by these parser/rule tests.

Add the following file as packages/rules/tests/integrity-text-boundary.test.ts in the upstream repository:

import { expect, test } from "bun:test";
import { parsePage } from "@squirrelscan/parser";
import { detectPageSignals } from "../src/integrity/signals";
import { brandImpersonationRule } from "../src/integrity/brand-impersonation";
import { fakeAuthOverlayRule } from "../src/integrity/fake-auth-overlay";
import type { RuleContext } from "../src/types";

const url = "https://example.com/";
const overlay = '<iframe id="google-auth" srcdoc="" style="position:fixed;top:0;left:0;width:100vw;height:100vh;z-index:9999"></iframe>';
const link = '<a href="https://credential-fixture.invalid/signin">Sign in with Google</a>';
function context(body: string): RuleContext {
  const html = `<!doctype html><html><head><title>Applicability fixture</title></head><body><main><h1>Applicability fixture</h1>${body}</main></body></html>`;
  const parsed = parsePage(html, url);
  return { page: { url, html, statusCode: 200, loadTime: 0, headers: {}, parsed }, parsed, options: {} };
}

test("control: whitespace-separated correlated signals produce two failures", () => {
  const ctx = context(` ${overlay}${link}`);
  expect([...detectPageSignals(ctx)].sort()).toEqual(["brand-impersonation", "fake-auth-overlay"]);
  expect(brandImpersonationRule.run(ctx).checks[0]?.status).toBe("fail");
  expect(fakeAuthOverlayRule.run(ctx).checks[0]?.status).toBe("fail");
});

test("regression: removing inter-element whitespace preserves correlated signals", () => {
  const ctx = context(`${overlay}${link}`);
  expect([...detectPageSignals(ctx)].sort()).toEqual(["brand-impersonation", "fake-auth-overlay"]);
  expect(brandImpersonationRule.run(ctx).checks[0]?.status).toBe("fail");
  expect(fakeAuthOverlayRule.run(ctx).checks[0]?.status).toBe("fail");
});

test("control: a lone overlay remains info", () => {
  const ctx = context(` ${overlay}`);
  expect([...detectPageSignals(ctx)]).toEqual(["fake-auth-overlay"]);
  expect(fakeAuthOverlayRule.run(ctx).checks[0]?.status).toBe("info");
  expect(brandImpersonationRule.run(ctx).checks).toEqual([]);
});

test("control: an ordinary iframe has no compromise signal", () => {
  const ctx = context(' <iframe title="Ordinary content" srcdoc="" style="width:300px;height:150px"></iframe>');
  expect([...detectPageSignals(ctx)]).toEqual([]);
  expect(fakeAuthOverlayRule.run(ctx).checks).toEqual([]);
  expect(brandImpersonationRule.run(ctx).checks).toEqual([]);
});

Run: bun test packages/rules/tests/integrity-text-boundary.test.ts.

Actual (Bun 1.3.11, source test, 2026-10-12): three controls pass; the compact-markup regression fails because detectPageSignals returns only fake-auth-overlay instead of brand-impersonation plus fake-auth-overlay. The spaced control produces two fail checks. The single-overlay control remains info; the ordinary iframe produces no signal.

Cause. The exported parsePage uses extractContent in src/html.ts, which clones the body, removes scripts/styles and reads clone.textContent without block separators. The compact fixture becomes Applicability fixtureSign in with Google. In detectBrandImpersonation, the page-wide hasCredentialAffordance word-boundary regex fails before the independently labelled credential link is considered. The link's own text is still Sign in with Google; its destination remains off-brand.

Expected. Inter-element whitespace must not determine whether an explicitly brand-labelled, off-brand credential control is recognized. Preserve the ordinary iframe, the lone-signal info behavior, legitimate provider links and self-hosted authentication. A missing page-wide word boundary should not override the credential control's own evidence. No new network probes are needed.

Local action. No rule disabled and no production/Overhub detection changed. Existing zero-check localhost runs do not prove integrity is disabled: this fixture loses correlation, and lone info findings also meet the separately tracked report visibility limitation #669. Published CLI confirmation remains separate from this source-level reproduction.

The existing integrity.test.ts suite also passes: 68 tests, 138 assertions. The reproduction and corrected source attribution were independently reviewed before filing.

Acceptance Criteria

  • The reporter's regression test (integrity-text-boundary.test.ts) is added and passes: removing inter-element whitespace between the auth iframe and the off-brand "Sign in with Google" link still yields both brand-impersonation and fake-auth-overlay signals.
  • fake-auth-overlay still reports fail (not info) when the correlated brand signal is present, with or without whitespace.
  • Text extraction used by detectPageSignals inserts a boundary between adjacent block/inline-block elements so words from different elements are not glued together.
  • No new false positives: existing integrity rule tests and the streaming-rules canonical golden test pass unchanged (or the golden change is explained in the PR).
  • Any other rule built on the same text extraction is checked for the same gluing bug, and the result is noted in the PR.

Activity

  1. added
    bug
    P3
    rules
    security
    size: M
    on Oct 13, 2026
  2. nc9 commented on Oct 13, 2026

    @nc9
    Contributor

    Spec prep

    Verdict: confirmed on current main (e95e0f5, v0.0.112). Confirmed by reading the code; the reporter's test was not re-run.

    • packages/parser/src/html.ts:379-417 (extractContent) still clones <body>, drops scripts and styles, and reads clone.textContent with no separators. The compact fixture becomes Applicability fixtureSign in with Google.
    • packages/rules/src/integrity/signals.ts:247-300 (detectBrandImpersonation) gates everything on hasCredentialAffordance: a password input, or /\b(sign in|log in|login|enter your password|verify your account)\b/ over title + "\n" + content.textContent. In fixturesign in there is no \b before sign, so it returns null.
    • credentialDestinations() has already found the link, labelled it Google from its own text, and resolved an off-brand host. That evidence is computed and then ignored.
    • detectFakeAuthOverlay has the same page-wide test (pageHasAuthAffordance, signals.ts:412-418), which its off-self iframe branch needs. In this fixture the overlay still fires through the google-auth id, which is why it drops to info instead of vanishing.

    Change (in signals.ts only, no parser change)

    1. The control's own evidence. Compute credDests before the gate, and treat credDests.length > 0 as a credential affordance. Every entry is already either a password form or a link whose own text matches AUTH_LABEL. This alone fixes the reporter's regression.
    2. Boundary-aware text for the signals (criterion 3). Add signalText(ctx), memoised per Document in a WeakMap the same way signalCache is. Use it in place of ctx.parsed.content.textContent in detectBrandImpersonation, detectFakeAuthOverlay and detectSeoDoorway. Build it on packages/rules/src/content/text-content.ts:
      • getRenderedProseText(body) puts a newline at each block boundary and skipped subtree, which covers this fixture (h1 is a block).
      • Treat replaced elements (iframe, img, input, button, select, textarea) as boundaries too, but not every inline node. <span>Goo</span><span>gle</span> should still read as google, as a browser shows it. getSeparatedText splits every node, so it would lose that.
    3. Leave extractContent alone. Its textContent feeds wordCount, contentHash (duplicate content, page_features.content_hash, the rule cache key), isThinContent and the cloud textExcerpt. A parser-wide boundary fix is a separate, much larger change; file a follow-up if we want it.

    Criterion 5: other readers of parsed.content.textContent

    • integrity/kit-signature.ts:55 passes it as text to intel signature matching. Same gluing. Switch it to signalText in the same PR.
    • schema/rating-scope.ts:353 (visibleText) runs VISIBLE_RATING_PATTERNS, which are \b-anchored, over it. <span>Rating</span><span>4.8</span> reads Rating4.8, so a visible rating can be missed and give a false "not visible" warning. This is a real candidate: fix it here or file a follow-up (see open questions).
    • audit-engine/src/cloud-prefetch-run.ts:101 (textExcerpt) is not a rule.
    • The content/* rules already read text through the text-content.ts helpers, so they are not affected.

    Tests

    • Add the reporter's packages/rules/tests/integrity-text-boundary.test.ts verbatim (4 tests). Add:
      • a compact legit Sign in with Google link to accounts.google.com: no brand-impersonation;
      • a compact off-brand link with no overlay: the brand-impersonation signal alone, at info;
      • the inline-split brand case (Sign in with <span>Goo</span><span>gle</span>), pinning whichever behaviour we choose.
    • Re-run integrity.test.ts (68 tests), integrity-cloaking.test.ts and integrity-intel.test.ts with explicit paths.
    • Goldens, one at a time: packages/audit-engine/tests/streaming-collector-rules-golden.test.ts (integrity/orphan-page and template-discontinuity read detectPageSignals through collected-signals.ts), then streaming-rules-canonical-golden.test.ts. Both compare v1 with v2 running the same code, so I expect them green. If the seeded fixture's tally moves, explain it in the PR.

    Docs, skills, completions

    • docs/rules/integrity/brand-impersonation.mdx and fake-auth-overlay.mdx: one sentence each saying page copy is read with element boundaries and that a brand-labelled sign-in control counts as auth copy on its own. Run make validate.
    • No skill or completion change.

    Risks

    • A boundary can now create a sign in match where glued text hid one, so a few pages may gain a signal.
    • Escalation to fail still needs two distinct signals, and brand impersonation still needs a brand-labelled control with an off-brand destination. The false-positive guard stays where it is.
    • Cost is one extra body walk per page, memoised.

    Open questions for the maintainer

    1. Boundaries at block and replaced elements only (recommended), or between every node?
    2. Fix schema/rating-scope in this PR, or file a separate issue? I recommend a separate issue: it is a different rule family with its own fixtures.

    Recommended session

    Sonnet, high effort (detection heuristics with false-positive guards). Size M confirmed. It would be S if limited to change 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3bugrulessecuritysize: M

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions