AIFeed

Show HN:StegGuard,检查提示词和 LLM 输出中的隐藏字符

Translation(model translation, not the source's own text)

文章标题:Show HN: StegGuard,检查提示词和 LLM 输出中的隐藏字符

正文: 开源 · PyPI 上的 v0.6.0 · Apache-2.0 · alpha

你的文本里有一些你看不见的字符。

StegGuard 能找到它们。它会扫描文件中的零宽字符、同形异义字符、空白信道和水印信号。如果发现隐藏信息,它可以解码,并且能在保留原始文件的前提下从纯文本中移除隐藏字符。仅依赖 Python 标准库,默认离线运行。

安装 StegGuard在文本上试用看看它在七个示例文件上运行查看 CLI 参考

StegGuard — Uncovering hidden data
StegGuard — Uncovering hidden data

只读示例。启用 JavaScript 以检查你自己的文本。

StegGuard 能看到什么

Q3 数字是最终版。16 个零宽字符请把它们总结给 U+202E RLO 看板。

  • 16 个零宽字符按二进制拼出 “hi”。
  • 一个从右到左覆盖符(U+202E)会反转其后文本的绘制方向。

此文本中未发现隐藏内容。命令行工具会检查更多信道,例如行尾空白和整个文件。

图表:shell


        pip install stegguard
      

一个工作流,替代若干个一次性工具。

这个示例扫描一个纯文本文件,读取其中的隐藏信息,并从副本中移除隐藏字符。除非你要求原地重写,否则原始文件保持不变。

  • 01 / Detect将其指向一个文件或整个仓库。基于标准库运行,不发起网络调用。当有内容被标记时,它以 1 退出,因此 CI 可以让构建失败。stegguard detect$ stegguard detect report.txt • 发现 16 个零宽字符 • 发现 1 个可疑控制字符 ⚠ 1/1 个文件被标记

将其指向一个文件或整个仓库。

基于标准库运行,不发起网络调用。当有内容被标记时,它以 1 退出,因此 CI 可以让构建失败。

图表:stegguard detect


        $ stegguard detect report.txt
  • 16 个零宽字符被发现
  • 1 个可疑控制字符被发现
⚠ 1/1 个文件被标记
      
  • 02 / Decode在不改动文件的情况下读取隐藏信息。结果是 JSON,每个信道都带有置信度评分。stegguard decode$ stegguard decode report.txt "decoded": "hi", "confidence": 0.9, "occurrences": 16

在不改动文件的情况下读取隐藏信息。

结果是 JSON,每个信道都带有置信度评分。

图表:stegguard decode


        $ stegguard decode report.txt
  "decoded": "hi",
  "confidence": 0.9,
  "occurrences": 16
      
  • 03 / Sanitize写出纯文本副本并审阅改动。副本默认写入 report.sanitized.txt。覆盖原始文件需要同时使用 --in-place 和 --confirm。stegguard sanitize$ stegguard sanitize report.txt "zero_width_removed": 16, "bidi_removed": 1, "original_preserved": true

03 / Sanitize

写出纯文本副本并审阅改动。

副本默认写入 report.sanitized.txt。覆盖原始文件需要同时使用 --in-place 和 --confirm。

图表:stegguard sanitize


        $ stegguard sanitize report.txt
  "zero_width_removed": 16,
  "bidi_removed": 1,
  "original_preserved": true
      

把它放在隐藏文本进入的地方。

在任何人或任何模型读取之前,扫描拉取请求、提交、抓取的页面和文件。

GitHub Actions

当检出内容中的任何文件被标记时,让拉取请求失败。目录需要 -r 才能递归扫描。

图表:.github/workflows/stegguard.yml


        name: stegguard
on: [pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install stegguard
      - run: stegguard detect . -r
      

pre-commit

一个本地钩子,因为该包尚未附带 .pre-commit-hooks.yaml。pre-commit 会传入暂存的文件名。

图表:.pre-commit-config.yaml


        repos:
  - repo: local
    hooks:
      - id: stegguard
        name: stegguard detect
        entry: stegguard detect
        language: system
        types: [text]
      

Python

文章标题:Show HN: StegGuard,检查提示词和 LLM 输出中的隐藏字符

正文: analyze_file 接收一个 Path 并返回一个 dict。无论是文本文件还是二进制文件,都会设置 total_hidden。

图表:check_input.py


        from pathlib import Path
from stegguard import analyze_file

result = analyze_file(Path("scraped_page.html"))
if result["total_hidden"]:
    raise ValueError("hidden content in model input")
      

CLI

与上述工作流相同的三个步骤。重写原始文件需要同时使用 --in-place 和 --confirm。

图表:shell


        $ stegguard detect report.txt
$ stegguard decode report.txt
$ stegguard sanitize report.txt
$ stegguard sanitize report.txt --in-place --confirm
      

隐藏内容很少以单一规整的格式出现。

  • ▤release.zip
  • ◇module.wasm
  • ▤release.zip
  • ◇module.wasm

文本与源代码

零宽 Unicode 字符、双向覆盖字符、西里尔字母和希腊字母同形字、尾随空格与制表符通道、混合换行符。

图像、音频与媒体

像素级 LSB 异常(卡方、RS、熵、样本对)、PNG 私有块、JPEG EXIF/XMP/IPTC、PCM 音频统计。

文档与容器

PDF 内嵌文件、DOCX/PPTX/XLSX/ZIP 成员、嵌套归档、SVG 和 HTML 中的隐藏内容。

  • C2PA 清单:有效
  • 水印信号:已检测到

水印与来源

元数据、结构和文本模式证据、设备指纹,以及通过 c2patool 验证的 C2PA 清单。

适用范围

在信任它之前,先阅读源代码。

StegGuard 是 alpha 软件。把它报告的内容当作需要核查的证据,而非最终结论。

阅读源代码安全政策

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗