Skip to content

detect(): sensitive-file filter silently drops any path containing 'token', 'secret', 'password'… #2106

Closed

Description

@psoholt

Summary

detect() silently excludes any file whose name or full path contains token, secret, credential, passwd, password, or private_key — as a bare substring, with no word boundaries and no regard for file type.

In a markdown knowledge base this drops ordinary prose articles. Three files in my corpus had never been in the graph across many runs:

wiki/ai-token-economics.md         <- a heavily-linked hub node
wiki/privacy-tokens.md
wiki/chain-of-hope-tokenomics.md

The exclusion is invisible in normal use: the paths land in skipped_sensitive, but the /graphify skill flow only reports a count ("mention file count skipped, not the file names"), so nothing tells you which files vanished or why. I only found it by diffing the manifest against ls wiki/.

Source

graphify/detect.py (v0.4.23):

_SENSITIVE_PATTERNS = [
    ...
    re.compile(r'(credential|secret|passwd|password|token|private_key)', re.IGNORECASE),  # L36
    ...
]

def _is_sensitive(path: Path) -> bool:
    name = path.name
    full = str(path)
    return any(p.search(name) or p.search(full) for p in _SENSITIVE_PATTERNS)

Because full = str(path) is also tested, one directory named e.g. secrets/ or password-reset/ silently removes an entire subtree from the corpus.

Reproduce

from pathlib import Path
from graphify.detect import _is_sensitive

_is_sensitive(Path("notes/ai-token-economics.md"))       # True  (expected False)
_is_sensitive(Path("docs/password-reset-design.md"))     # True  (expected False)
_is_sensitive(Path("research/tokenization.md"))          # True  (expected False)

Second-order bug: --update then deletes the recovered nodes

This is the part that cost me the most time. If you work around the filter by force-including the files (so they appear in graphify-out/manifest.json), the next --update is destructive:

detect_incremental() still excludes them, so comparing against the manifest reports them as deleted_files, and the merge step runs G_existing.remove_nodes_from(...) — silently pruning ~70 nodes that had just been recovered. So the workaround makes the next incremental run worse than no workaround at all.

Suggested fix

Exempt markdown-family extensions from the broad keyword pattern only, keeping every strict pattern (.env, .pem, id_rsa, .netrc, aws_credentials, …) applying to all files:

_PROSE_EXTS = {".md", ".markdown", ".rst", ".org"}
_KEYWORD_PATTERN = re.compile(
    r'(credential|secret|passwd|password|token|private_key)', re.IGNORECASE)

def _is_sensitive(path: Path) -> bool:
    name, full = path.name, str(path)
    is_prose = path.suffix.lower() in _PROSE_EXTS
    for p in _SENSITIVE_PATTERNS:
        if is_prose and p.pattern == _KEYWORD_PATTERN.pattern:
            continue
        if p.search(name) or p.search(full):
            return True
    return False

Real secrets live in dotfiles, keys and configs — not in .md notes. I deliberately left .txt guarded, since token.txt / access_token.txt are plausible credential dumps.

Verified against my corpus: 98 -> 101 documents detected, skipped_sensitive empty, and all of .env / .env.local / *.pem / secrets.json / api_token.json / credentials.yaml / id_rsa / .netrc / aws_credentials / token.txt still correctly blocked.

Two smaller things that would have made this self-diagnosing:

  1. Match on the filename only, not the full path — or at least only the path segment(s) below the corpus root. A parent directory name shouldn't silently disqualify a subtree.
  2. Name the skipped files (behind a flag if you like). A bare count reads as "nothing important happened".

Happy to open a PR if the approach looks right.

Activity

  1. safishamsi commented on Jul 22, 2026

    @safishamsi
    Member

    Fixed in v0.9.24. The sensitive-file filter no longer silently drops topic docs or real source: service_account/aws_credentials moved to the boundary-checked keyword path (real source spared, downloaded key files still excluded), a prose-note carve-out was added, and missed secret dotfiles (.npmrc, .pypirc, .git-credentials, secring, case variants) are now caught. graphify extract and the skill flow also name the skipped files instead of only a count. https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.24

  2. psoholt commented on Jul 23, 2026

    @psoholt
    Author

    Upgraded 0.4.23 → 0.9.25 and can confirm this is fixed. Thanks for the thorough rewrite — the three-stage split is a better fix than the extension-exemption I suggested.

    Verified on my corpus (100+ markdown wiki articles):

    • ai-token-economics.md, privacy-tokens.md, chain-of-hope-tokenomics.md now detected; skipped_sensitive is empty.
    • Still correctly blocked: .env, .env.local, *.pem, secrets.json, api_token.json, credentials.yaml, id_rsa, .netrc, token.txt, access_token.txt — plus .npmrc and .git-credentials, which the old code let through.
    • The second-order --update problem is gone too: detect_incremental against a pre-upgrade manifest (relative paths) reported 0 deletions, so no nodes were pruned. The relative→absolute path change was handled transparently.

    Two notes for anyone else upgrading across this range: detect() now returns absolute paths and gained gitignore=True, and 0.9.x classifies some config/CI files (.mcp.json, .github/**) as corpus, so you may want to extend .graphifyignore. Both were easy to absorb — every function signature change was additive.

  3. added a commit that references this issue on Jul 26, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions