Skip to content

fix(rules): keyword-stuffing: German function words, link-list menus, per-card microcopy #1315 - #1345

Closed
nc9 wants to merge 6 commits into
mainfrom
fix/keyword-stuffing-1315
Closed

nc9 wants to merge 6 commits into
mainfrom
fix/keyword-stuffing-1315

Conversation

@nc9

@nc9 nc9 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1315

Three false-positive classes on a German shop (brunobanani.com, from the issue):

  1. German function words (sie, für, dich, dir, deinen, deinem, deiner, ihn, ihm and a few inflections (the two-letter ones from the issue, du zu im am ob so, are below the 3-character token minimum and were never counted)) and English out are filler.
  2. Menu chrome built from plain divs: on the body-fallback path, blocks that are at least 85% link text with at least 6 links and 4 different labels AND a menu signal (a list of links, or menu/nav/dropdown naming up to 3 wrappers up) are left out. One anchor repeated 20 times, or a bare div of keyword links, is not a menu and still flags.
  3. Product-card microcopy: a short text that is the whole text of an element, in at least 3 different parent wrappers, digits ignored, and not the whole text of its wrapper, is a UI component (deducted like the CTA allowlist). The same sentence repeated in one container is body copy and still flags.

Tests: packages/rules/tests/keyword-stuffing.test.ts (each AC, both true-positive controls, and a bounded-cost test with 6000 nested anchors and 6000 cards); the new German, out, menu and card tests fail on main. Local smoke on the issue's site (30 pages, rule only) still reports a few words on one aggregated check (bestellung, jetzt, newsletter, ...); not claiming it is clean.

Known cost, stated in the rule docs: a page whose copy is a long list of different link labels reads as a menu, and a stuffed phrase repeated in separate wrappers that each hold only that phrase reads as a card.

Docs: docs/rules/content/keyword-stuffing.mdx, CHANGELOG under Unreleased. Skill: none.

Review round: the two false negatives (25 wrappers each holding only the phrase; a bare div of 24 keyword links) are tests that flag now, with the controls; card bound counts candidate cards (4,000) and scanned elements (40,000), tested with 700 cards.

Round 2 (review + security scan): card deduction now only for NUMERIC text whose digits differ between occurrences in >=3 wrappers (a stuffed phrase repeats identically, so it can never be a card: your 25x div>(p phrase + p call N) and ul>(li phrase + li more info) flag; identical-digit phrases flag); no parent text is read at all (the quadratic parent.textContent is gone; every leaf counts toward the 4,000/40,000 bounds); link-list exclusion needs a real signal (role menu/menubar/navigation, aria-haspopup/aria-expanded), class/id names and plain ul>li dropped, plus a keyword-cloud guard (a word in >=60% of labels): div.nav, #footer-menu, bare ul>li and role=menubar clouds of 24 keyword links flag. Timing tests (40k spans, 3,000 cards under a 2M-char parent, 8k li, 2,000 groups under 500-char classes) all < 1.5 s on the loaded box.

Round 3: only rating/price-shaped numbers (decimal, amount with currency, %, 4 of 5, star/review counts) make a card; bare integers (doorway numbering) never do (the three digit-varying repros flag); card deduction capped at 20% of the words; keyword-cloud share lowered to 30% (tests at 40% and 58%, with role=menubar and aria-expanded); costs documented: real menus repeating a word and plain-div menus with no signal count, bare counts and non-numeric card text count, card bound is ~400 cards.

@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1345. The change is scoped and well tested, and I found nothing that should block merge. Remarks below.

  • (medium) keyword-stuffing.ts card heuristic: a stuffer can bypass the rule by wrapping the target phrase in three or more separate wrappers, for example one <div><span>cheap loans online</span></div> per block. The PR docs state this cost. Consider requiring that the repeated text be structurally similar (same tag and class) or that the sibling wrappers share a grid parent, so one-off sections do not qualify. Alternatively, cap the share of organicTotal that card deduction can remove, so a page of nothing but "cards" still gets scored.
  • (low) The card deductions are added to ctaWordDeductions and ctaWordTotal with no overlap check against the CTA allowlist. A <span>Add to cart</span> inside an <a> or <button> is counted in both passes, and organicTotal is shrunk twice. Skip card leaves that have an a, button ancestor, as the CTA pass does for nested controls.
  • (low) ctaWordTotal adds every token of the card text, but words may not contain all of them. Stop words and short tokens are filtered in some paths. If so, organicTotal is under-estimated and densities are inflated slightly. Only count tokens that are present in wordCounts.
  • (low) createLinkListTest calls element.textContent for every candidate block. That is bounded by 3000 anchors times depth 8, and the 6000-anchor test covers it. Reading the first uses of textContent only after the link and label thresholds pass, as it already does, is enough. Fine as is.
  • (nit) The link-list heuristic only applies on the body-fallback path. The <main> path with under 100 words still falls through to it, so the doc phrase "no main copy of its own" is correct. A one-line test for that fall-through would help.
  • (nit) The timing test asserts under 3 s on shared CI. The repo guidance prefers asserting an effect over elapsed time, and the existing bound will not flake much. Consider also asserting that the call returns a check.

Docs and CHANGELOG are updated. Registry tests are not affected, because no rule id was added or changed. I did not run the tests locally.

@nc9
nc9 force-pushed the fix/keyword-stuffing-1315 branch from 9cf9ef5 to af3ba05 Compare October 30, 2026 08:58
@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1345. The change is well scoped, and the true-positive controls are good. I read the diff only and did not run the tests or the benchmarks.

  • (medium) packages/rules/src/content/keyword-stuffing.ts repeatedCardText: (parent.textContent || "").replace(...).trim() runs for every candidate leaf, so the cost is O(candidates × parent text size). The bounds count elements, not characters. A page with a few thousand short <p> or <li> leaves under one large container (an article or a long list, 400KB of text) builds and normalizes that container's text once per leaf. That is roughly 4,000 × 400KB of string work in untrusted-input code that runWithinBudget can't interrupt. The new bounded-cost test doesn't catch it, because its cards have tiny parents. Compute the parent's normalized text once per parent (a Map<Element, string>), or cap the parent text length. A cheaper check is whether the parent has other text-bearing children, for example parent.children.length > 1 or comparing text lengths. Add a test with 4,000 short paragraphs in one container.
  • (low) hasMenuSignal: element.querySelector("ul > li, ol > li") accepts any descendant list, so a link cloud with one unrelated <ul><li> inside it gets the menu signal. A spammer can add that cheaply. Consider requiring most of the block's anchors to sit inside li elements.
  • (low) MENU_NAME matches nav as a separate token in any class or id up to 3 wrappers above the block. A wrapper like class="nav-hero" or class="mega-deals" around copy-style links would count as a menu. This is partly documented as a known cost, but a test pinning the intended behavior would help.
  • (nit) The card deduction adds to ctaWordDeductions. If the same text is also matched by the CTA allowlist, it can be deducted twice. A test with a CTA label such as "Learn more" repeated per card would confirm that.
  • (nit) The tests don't cover the docs claim that the link-list test applies only on the body-fallback path. Add a case where a <main> with at least 100 words and a div mega menu is still measured as before.

No critical or high findings.

@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1345 (keyword-stuffing false positives). The change is scoped and well tested. I read the diff only and did not run the tests. CI was still pending when I looked.

  • (medium) keyword-stuffing.ts repeatedCardText: a stuffer can evade the card deduction's guard by varying a digit. cheap emergency plumber london 1, ... 2, ... 3 in three or more wrappers have differing digits and at least 3 parents, so every word of the phrase is deducted from both the count and the denominator. The docs describe the identical-digit case as safe, but a varying-digit phrase is a cheap bypass of the rule's main purpose. Consider requiring the non-digit remainder to be a small share of the page, or capping how much of the total the card deduction can remove (e.g. a percentage of words.length). Adding a test for this shape would document the residual either way.
  • (low) hasMenuSignal: aria-expanded and role=navigation are trivial to add, so the signal is only as strong as isKeywordCloud. A spammer with link labels that share no single word at 60% gets the whole block excluded. This is acknowledged in the docs. A note in the PR that the residual was accepted would help.
  • (low) createLinkListTest: element.textContent is read for every ancestor that passes the cheap tests, up to 8 levels per anchor with 3000 anchors. Large nested signalled wrappers each re-serialize big subtrees. The timing tests do not cover signalled and nested ancestors (the nested-anchor test has no role), so the expensive path is untested for cost. Consider adding a role=menubar variant to the bounded-cost test.
  • (nit) The timing tests assert fixed wall-clock thresholds (1.5 s / 3 s). These could flake on loaded CI. AGENTS.md prefers asserting an effect, or a 4x-scaling check.
  • (nit) LINK_LIST_MAX_DEPTH = 8 and the depth < 4 in hasMenuSignal are two separate magic numbers. A named constant for the 3-wrapper limit would match the docs wording.

@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1345 (keyword-stuffing false-positive fixes). I read the diff only and did not run the tests or the smoke test.

  • (medium) keyword-stuffing.ts createLinkListTest: the final loop calls element.textContent on every ancestor (up to 8 levels per anchor) that passes the link-count, menu-signal and cloud checks. Nested wrappers that all carry aria-expanded or sit inside a role=navigation block can each concatenate a large subtree. That is up to 8 levels × many candidates over a big page, which is quadratic-ish. The new bounded tests only exercise nested plain divs, which have no menu signal and so skip this path. Please add a hostile fixture with signalled nested wrappers and a large text body, or cap the number of textContent reads.
  • (low) isKeywordCloud only samples the first 60 labels (LINK_CLOUD_SAMPLE). A spammer can put 60 varied labels first and the stuffed phrase after them, and the block is then excused. This is acceptable as a stated heuristic, but the docs should say it.
  • (low) Spam escape hatch: aria-expanded or aria-haspopup on any ancestor within 3 levels counts as a menu signal. Anyone can add those attributes, unlike the stronger role signals. The new test covers only role=menubar and aria-expanded with a cloud. Consider a test with a mixed-label stuffed block under aria-expanded to document the residual.
  • (low) The timing assertions (<1500 ms and <3000 ms) can be flaky on loaded CI. AGENTS.md prefers asserting an effect, or checking that time scales roughly linearly, over absolute thresholds.
  • (nit) repeatedCardText: when one entry would overflow cardWordCap, continue skips it entirely rather than partially deducting. This is deterministic but depends on Map insertion order. A short comment would help.
  • (nit) CARD_NUMBER is a shared global regex with lastIndex reset by hand. A non-global test regex plus a separate replace regex would be less fragile.

AGENTS.md checklist: the CHANGELOG entry and docs update are present, and no perRuleTally key is added. I did not verify the golden-pin test or the registry-wide tests.

@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Reviewed keyword-stuffing.ts, the docs and the CHANGELOG entry. I didn't run the tests. No blocking problems found.

  • (low) keyword-stuffing.ts createLinkListTest: isKeywordCloud looks only at the first 60 labels of each block (LINK_CLOUD_SAMPLE). A stuffer who puts 60 varied labels first and the keyword-heavy links after them, inside a role="navigation" wrapper, evades the cloud test. The menu signal is cheap to fake, and the docs already accept that. Sampling labels spread across the whole block would be a cheap hardening.
  • (low) createLinkListTest: element.textContent is read for every candidate that passes the signal test. Nested role="navigation" wrappers can reach about 3000 anchors × 8 levels, so a hostile page could make this quadratic. The anchor and depth caps bound it, but I'd cap the text read, or memoise the text length per element, and add a hostile-page test like the existing 6000-anchor one but with signal attributes on every level.
  • (low) repeatedCardText: CARD_NUMBER is a module-level /g regex shared across calls, and the code resets lastIndex by hand. That is correct as written, but a non-global copy for .test would be more robust.
  • (nit) The PR description says the menu signal is "a list of links, or menu/nav/dropdown naming". The code and docs (rightly) say class and id names and plain lists don't count. Please update the description so it matches.
  • (nit) The card-deduction block in run() is getting long. Pulling it into a helper would make run() easier to read.

Tests cover the true-positive controls and the bounded-cost cases, and the docs state the trade-offs.

nc9 added 6 commits October 31, 2026 06:22
…without landmarks, per-card microcopy #1315

Signed-off-by: Nik Cubrilovic <[email protected]>
… the whole text of its wrapper, no two-letter words, bound counts candidates #1315

Signed-off-by: Nik Cubrilovic <[email protected]>
…nu signal and keyword-cloud guard, linear time #1315

Signed-off-by: Nik Cubrilovic <[email protected]>
… card, 20% cap, keyword-cloud share 30% #1315

Signed-off-by: Nik Cubrilovic <[email protected]>
…ped deduction with a per-word floor and a raw-density limit #1315

Signed-off-by: Nik Cubrilovic <[email protected]>
… of a card number are deducted with the card #1315

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/keyword-stuffing-1315 branch from 15e8343 to 7aee982 Compare October 30, 2026 19:23
@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of the keyword-stuffing changes. I read the diff only and did not run the tests.

No critical or high issues. The code is bounded: anchors, depth, card candidates and scanned elements are all capped, and the card deduction is clamped by share and by a per-word floor. The docs, CHANGELOG and code agree on the menu-signal definition.

  • (medium) keyword-stuffing.ts (hasMenuSignal): a page author can bypass the link-list exclusion by adding role="navigation" or aria-expanded to a stuffed block. The only guard is the 30% shared-word keyword-cloud check. A spammer who varies the labels so that no single word reaches 30% (for example 4 or more labels, each with 2 different keywords) is excluded entirely. The docs admit a cost in the other direction, but not this evasion. Consider adding a regression test for it. Consider also requiring the role="navigation" block to be a real landmark (a nav element, or the role on the block itself rather than a wrapper up to 3 levels above). A wrapper signal currently covers every link-heavy descendant block.
  • (low) createLinkListTest: every a in the body adds an entry to stats for each of up to 8 ancestors. With 3000 anchors that is about 24k entries, each holding a sample array of up to 60 strings. This is bounded but allocation-heavy for a fallback path. Only populating sample for elements that pass the count test would trim it.
  • (low) repeatedCardText: the CARD_NUMBER regex is global and shared at module level, and lastIndex is reset by hand around .test. It is correct as written, but fragile. The pattern is also bounded only by the 160-char text cap. That is fine for the cap, but worth a comment.
  • (nit) The PR body still describes the menu signal as "a list of links, or menu/nav/dropdown naming". The code and docs now use role and aria attributes only. Update the description so it does not mislead reviewers.
  • (nit) The card deduction is hard to follow across several steps (cardDeductions, cardApplied, floorCount). A short summary comment of the invariants would help.

Tests cover each new class plus the true-positive controls and the bounded-cost cases. Per AGENTS.md, I could not confirm the golden pins, the registry-wide tests or the template-verdict tests. CI should confirm them.

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.145 as 8a23839b 146dff5a e96405ed 98d074eb d50345c6 845fa2f0 via #1377. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.145. Closing this original.

nik

@nc9 nc9 closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

content/keyword-stuffing: missing German function words, menu chrome on short pages, product-card microcopy (v0.0.141)

1 participant