Skip to content

feat(security): build a narrow GlassWorm-style detector for obfuscation_flag - #1169

Merged
squid-protocol merged 1 commit into
mainfrom
fix/1150-glassworm-detector
Aug 9, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/1150-glassworm-detector

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Resolves #1150's deferred design decision (originally deferred in #369): rather than formally
deprecating the always-0 obfuscation_flag column, this builds a real (deliberately narrow)
detector so the acceptance criteria's "build" path is satisfied without overreaching what a
regex-based, AST-free engine can credibly claim.

Two independent lexical proxies added to security_lens.py's THREAT_SIGNATURES, either
sufficient to set obfuscation_flag = 1:

  • unicode_steganography — a run of 3+ consecutive codepoints from the Unicode Variation
    Selector / Variation Selector Supplement / Tags blocks. This is the actual invisible-payload
    encoding technique the real GlassWorm npm campaign used. A single codepoint (ordinary emoji
    presentation, e.g. the VS16 in "❤️") is deliberately excluded from matching — only a run has
    no legitimate source-code use, since a useful hidden payload necessarily needs many consecutive
    invisible codepoints to encode anything.
  • self_propagation — a self-file-reference token (__filename/__dirname/
    import.meta.url in JS, __file__ in Python, __FILE__ in PHP/Ruby) passed as the literal
    first argument to a copy/write/rename call (fs.copyFileSync, shutil.copy, os.rename,
    etc.) — the mechanical signature of a worm duplicating or overwriting itself. Deliberately
    excludes bare self-reads (open(__file__), common for version banners) and loose "self-ref
    anywhere near a write" proximity windows (too FP-prone against ordinary path-resolution idioms
    like path.dirname(__filename)) — only the unambiguous "self-path handed straight into a
    mutating call" shape qualifies.

Explicitly not attempted: the multi-file/manifest-correlation angle from the issue
(install-script + registry-publish sequences spanning files). That needs execution/temporal
semantics this AST-free engine doesn't have — forcing it would be the overreach the issue itself
warned against.

Why the golden master changed

Both signals are new SIGNAL_SCHEMA entries (appended at the end, not inserted mid-list, to
avoid reindexing the K-Means archetype classifier's positional feature vector), so every scanned
file gains two new schema columns. I verified actual hit counts are zero across the full
1118-file language-crucible corpus
(44+ languages) before blessing the baseline via
update_golden_master.py — the corpus-wide diff (1873 differences) is purely the two new
zero-value columns appearing everywhere, not behavior drift. crucible_check.py passes clean on
both full-precision and zero-dependency modes after the rebless.

Test plan

  • New security_lens.py tests: both signals fire on synthetic malicious code (self-copy,
    self-overwrite, JS/Python variants, a hidden Unicode payload run) and do not fire on
    realistic benign code (ordinary emoji text, path.dirname(__filename), open(__file__)
    self-reads, unrelated os.rename calls)
  • test_record_keeper.py updated: obfuscation_flag now reads 1 when
    sec_self_propagation/sec_unicode_steganography fire, replacing the old hardcoded-0
    assertion
  • Full local suite: 671 passed, 1 xfailed
  • audit_check.py: ruff/mypy/dead-key all clear (baseline regenerated for pure line-shifts)
  • crucible_check.py: PASS on both full-precision and zero-dependency modes
  • ReDoS timing sweep on both new regexes (linear scaling confirmed up to n=200,000)

🤖 Generated with Claude Code

…on_flag (#1150)

Resolves #1150's deferred design decision (#369): rather than formally
deprecating the always-0 obfuscation_flag column, adds two deliberately
narrow lexical proxies to security_lens.py's THREAT_SIGNATURES, scoped to
keep both false positives and false negatives low:

- unicode_steganography: a RUN of 3+ consecutive Unicode Variation
  Selector/Tag codepoints -- the actual invisible-payload-encoding
  technique GlassWorm used. A single codepoint (common emoji presentation,
  e.g. "heart"+VS16) is explicitly excluded; only a run has no legitimate
  source-code use.
- self_propagation: a self-file-reference token (__filename/__file__/
  import.meta.url/etc.) passed as the literal first argument to a
  copy/write/rename call -- the mechanical signature of a worm
  duplicating or overwriting itself. Excludes bare self-reads and loose
  same-file proximity matches, both common benign idioms.

Both signals verified at zero hits across the full 1118-file
language-crucible corpus (44+ languages) before blessing the golden
master baselines, so the corpus-wide diff is purely the two new
zero-value schema columns, not behavior drift. Does not attempt the
multi-file/manifest-correlation angle (install-script + registry-publish
sequences) from the issue -- that needs execution/temporal semantics this
AST-free engine doesn't have, and forcing it would be the overreach the
issue itself warns against.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 9a66d11 into main Aug 9, 2026
28 checks passed
@squid-protocol
squid-protocol deleted the fix/1150-glassworm-detector branch August 9, 2026 17:39
squid-protocol added a commit that referenced this pull request Sep 3, 2026
…two evasive shapes (#1172, #1174) (#2695)

#1172 -- the `__FILE__` half of the alternation was dead code. The token was
accepted, but no PHP or Ruby copy/write function was ever paired with it, and
`__FILE__` appears only in PHP/Ruby source, which never calls `shutil.copy`.
Adds PHP (`copy`, `rename`, `file_put_contents`/`file_get_contents`), Ruby
(`FileUtils.cp`, `File.write`/`File.read`), PowerShell (`Copy-Item` with
`$PSCommandPath` / `$MyInvocation.MyCommand.Path`) and Shell (`cp`/`install`
with `$0`) -- the last two because self-copy into a startup folder or cron
directory is the classic dropper persistence step.

#1174 -- two equally worm-like shapes slipped through the
literal-first-argument rule: one bounded path-normalization wrapper
(`shutil.copy(os.path.abspath(__file__), dest)`) and read-then-write
(`fs.writeFileSync(dest, fs.readFileSync(__filename))`), a self-copy spelled
as two calls.

The precision rule from #1150/#1169 is unchanged: the self-reference token
must visibly, directly feed a copy/write call, never merely appear nearby.
Only the routes to that call widen. `$0` is accepted solely as a literal
argument to `cp`/`install`, since it is otherwise ubiquitous in usage banners
and logging -- 11 false-positive guards cover exactly those idioms, including
a `cp` whose flag takes a value (`cp -m 755 /src/a /dst/b`), which the first
draft of the flag repeat let through.

Verified over the whole language-crucible corpus (3366 files): zero hits
before, zero hits after. The signal fires nowhere in real corpus code, so
there is no golden-master movement and no bless -- which is also the
acceptance criterion #1172 asked for.

Every quantifier bounded (Engine Rule 14), with a detonation test per new
branch. Suite 7483 passed.

Co-authored-by: Joe Esquibel <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

obfuscation_flag / GlassWorm-style detector: needs a real design decision, not a code fix

1 participant