PKCS#8 private keys bypass the default credential scan for hosted compression and response caching
Description
Priority: P1. Provisional severity: High (credential confidentiality, conditional on the described configuration); no CVSS vector or CVE assignment is asserted by this review. High is retained for maintainer triage because an unencrypted private key can grant access and its exact bytes can cross a third-party processing boundary despite the enabled privacy guard. Hosted compression is opt-in and the recipient is operator-configured; those prerequisites, local-only caching, and absence of observed historical exposure limit the claim. This is not a default-install remote exploit, and the final severity remains subject to maintainer assessment.
The built-in credential scanner recognizes algorithm-labelled PEM private keys (BEGIN RSA PRIVATE KEY, etc.) but does not recognize PKCS#8 BEGIN PRIVATE KEY or BEGIN ENCRYPTED PRIVATE KEY headers. Consequently, the default-on privacy scan does not prevent these private keys from being sent to a configured hosted LLM compressor, and the response cache persists and replays them instead of applying its documented secret exclusion.
This is a private draft for maintainer triage, not a public disclosure. No actual user key, external provider request, or historical exposure was used or observed.
Affected scope and prerequisites
- Reproduced on main
3f37d009768d8820ef01e1e119c4ea85876e75f0, identifying itself as 0.6.3. - The v0.6.3 tag's scanner was separately loaded and also fails to detect a freshly generated PKCS#8 key. Follow-up inspection loaded the scanner from all 55 local stable release tags from v0.1.0 through v0.6.3: none recognized the PKCS#8 private-key header. For the automatically wired runtime filtering covered by this advisory, the affected package range is
>= 0.1.24, <= 0.6.3. The earlier scanner-only observations do not establish the same runtime filter bypass. - Historical mechanism differs: v0.1.0 exposes the compressor's optional
privacy_patternsargument but its manager does not pass it. Among those inspected tags, v0.1.24 is the first whose manager passes the configured default-on privacy patterns into hosted compression. Thus do not describe v0.1.0 as bypassing the same default-on guard present today; early releases lack that automatic check altogether. The current/tag-v0.6.3 exact-key transmission and cache probes remain the dynamic evidence; every historical release was not run end-to-end. Runtime response-cache, extraction, and indexing privacy gates first appear among inspected stable tags at v0.1.28; the cache gate was also statically confirmed at v0.5.0 and v0.6.2. Distinguish hosted-compression filtering from v0.1.24 onward and these additional runtime gates from v0.1.28 onward, rather than attributing every consequence to every affected release. - The dynamically reproduced compression transmission requires a tool response containing the PEM and opt-in
llm_summarycompression with a hosted provider (and a body exceeding the compression budget). The configuredprivacy_scan_enabledcan remain at its defaulttrue. The user-configured provider is the recipient; this is a failure of credential filtering, not an arbitrary attacker-selected destination. - Cache persistence is a separate consequence: it uses the default response-cache storage gate. No access to the private local cache by another user was demonstrated.
- An encrypted PKCS#8 key is still credential material but is not directly usable without its passphrase. The unencrypted case establishes the key-disclosure impact.
Root cause
src/memtomem_stm/proxy/privacy.py:143 requires (RSA|EC|OPENSSH|DSA|PGP) between BEGIN and PRIVATE KEY. Neither PKCS#8 header has a matching algorithm label. The remaining token/PII rules do not reliably match PEM-encoded key bodies.
proxy/manager.py passes CREDENTIAL_PATTERNS to LLMCompressor.compress() when privacy scanning is enabled. proxy/compression.py tests those patterns before _call_api(). proxy/cache.py independently uses contains_sensitive_content() to gate storage and replay. Both boundaries inherit the missing format coverage.
Offline reproduction and results
Environment: macOS 26.6.2 arm64, Python 3.13.2. A new disposable RSA key was generated with the installed cryptography library and serialized as PKCS#8 and as traditional RSA PEM. Nothing was printed except booleans and the format headers; temporary databases were deleted after the probe.
| Representation | Credential detected | Compressor API boundary reached | Cache hit |
|---|---|---|---|
| PKCS#8, unencrypted | false | true | true |
| PKCS#8, encrypted | false | true | true |
| Traditional RSA PEM control | true | false (privacy fallback) | false |
A second probe replaced the compressor HTTP client with httpx.MockTransport and exercised the real _call_api and OpenAI request serializer: the mock request's user message contained the exact unencrypted PEM. Network calls: zero. The tag v0.6.3 scanner also returned false for this generated PEM.
Minimal scanner/cache reproduction (only a disposable key; never use an operational key):
import tempfile
from pathlib import Path
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from memtomem_stm.proxy import privacy
from memtomem_stm.proxy.cache import ProxyCache
key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
pem = key.private_bytes(serialization.Encoding.PEM,
serialization.PrivateFormat.PKCS8, serialization.NoEncryption()).decode()
print("detected", privacy.contains_sensitive_content(pem, privacy.CREDENTIAL_PATTERNS))
with tempfile.TemporaryDirectory() as td:
cache = ProxyCache(Path(td) / "cache.db")
cache.initialize()
try:
cache.set("synthetic", "read_key", {}, pem, 60)
print("cached", cache.get("synthetic", "read_key", {}) is not None)
finally:
cache.close()
# Current: detected False; cached TrueRemediation and acceptance criteria
- Add bounded PEM-header recognition for the confirmed unencrypted and encrypted PKCS#8 formats, while preserving existing algorithm-labelled key coverage. Avoid an ever-growing list without a stated format policy; use valid serialized fixtures to justify any broader bounded header grammar. Public keys and certificates must remain negative controls, and adversarial long labels/whitespace must not create superlinear scanning.
- Additional review candidates (
SSH2 ENCRYPTED PRIVATE KEY,ANY PRIVATE KEY,DH PRIVATE KEY, and PuTTY key-file headers) were tested only as header strings. They are not confirmed additional end-to-end exposures. Validate actual supported private-key encodings before claiming coverage; assess PuTTY as a separate non-PEM format and state its support or exclusion explicitly. - Exercise the manager's default-on hosted-compression gate with a mock HTTP transport; each private-key format must fall back without dispatching a request.
- Test response-cache set/get and the existing privacy-policy migration/repair path against pre-existing affected rows. A pattern change must invalidate the privacy-policy fingerprint and remove affected legacy rows through the supported repair path, without clearing unrelated metrics. The existing fingerprint already hashes
DEFAULT_PATTERNS, so changing that vocabulary automatically changes the fingerprint; an extra epoch bump is not required merely for a pattern addition. - Include the statically confirmed extraction and library-mode indexing paths below in remediation tests, and audit remaining shared-pattern consumers such as telemetry. Coordinate the mirrored Core scanner fix before disclosure/release; this STM advisory does not establish Core's affected version range or report a demonstrated Core runtime leak. No separate Core advisory has been created by this review.
- Until patched, avoid routing private-key-bearing tools to external LLM compression and disable their response caching. This is a configuration mitigation, not a claim that truncation removes all private-key text from the trusted caller's response.
No product code was changed during this review.
Additional statically confirmed consumers and coordination
These observations broaden the review map; they do not replace runtime evidence:
| Consumer | Confirmed source behavior | Preconditions / evidence limit |
|---|---|---|
STM proxy/extraction.py:277 | Hosted LLM/HYBRID extraction checks the same CREDENTIAL_PATTERNS before dispatch. | Extraction is disabled by default. The manager path also requires an injected index engine and the minimum response size. No extraction HTTP dispatch was reproduced in this review. |
STM proxy/memory_ops.py:73, :323 | The common indexing predicate uses the full default scanner; extracted candidate Markdown is screened again before persistence. Auto-index can write the original response to local Markdown. | These are opt-in/library integration paths requiring the manager's index engine; the bundled server does not automatically index tool responses. Actual index/file persistence was not reproduced. |
Sibling Core packages/memtomem/src/memtomem/privacy.py:166 | At local Core HEAD 7e9d846c4fe9a22922af806a69545080d269965e, static inspection confirms the same algorithm-labelled PEM regex. | No Core runtime exploit or historical range was tested. Coordinate a private cross-repository fix/coverage check; do not assume STM's version range applies to Core. |
Historical evidence can be reproduced without network by reading git show <tag>:src/memtomem_stm/proxy/privacy.py for the local release tags and invoking each module's contains_sensitive_content on a synthetic PKCS#8 header. Inspect git show v0.1.0:src/memtomem_stm/proxy/manager.py versus v0.1.24 to distinguish absent automatic scanning from an enabled but incomplete scanner. Header-only tag checks establish scanner coverage, not a historical end-to-end exploit trace.
Historical lower-bound clarification
The advisory's machine-readable affected range tracks the bundled manager's enabled-but-incomplete privacy filtering, introduced in v0.1.24. In v0.1.0–v0.1.23, the scanner and optional LLMCompressor.compress(privacy_patterns=...) argument exist, but the manager does not supply the argument and the relevant automatic cache gate is absent. A library caller explicitly supplying patterns can encounter the same missing-format detection; that caller-dependent use is a separate historical caveat, not the basis for broadening this runtime advisory's lower bound. Older versions are not thereby declared safe for sensitive data: absence of a privacy guard is distinct from bypassing the guard covered here. Historical code/headers were inspected statically; end-to-end key-transmission evidence remains tied to the reviewed current source.
Patches
Fixed in 0.6.9. The fix merged as c5509694 and shipped in the 0.6.9 release (memtomem-stm#1231). The affected range extends to 0.6.8: every release from 0.1.24 through 0.6.8 carries the same rule. memtomem core shipped the same fix in 0.6.12 (GHSA-pfm2-fmvr-p8c8).
After upgrading, the first start runs the response cache's one-time privacy sweep, which removes cached responses carrying a PKCS#8 key. Rotate any key that may have reached a hosted provider.