Skip to content

security: harden file tools, SSRF, A2A auth, CAG KV-cache, deps (#1021–#1026) - #1027

Merged
AmitoVrito merged 10 commits into
mainfrom
security/hardening-1021-1026
Sep 8, 2026
Merged

AmitoVrito merged 10 commits into
mainfrom
security/hardening-1021-1026

Conversation

@AmitoVrito

Copy link
Copy Markdown
Collaborator

Security hardening sweep

Fixes a batch of vulnerabilities surfaced by a full security audit (OSV dependency scan of all 549 resolved packages + a multi-agent source review of the agent tools, loaders, RAG/CAG, A2A, and vector-store layers). Every finding was verified against the actual code before fixing. All changes are additive / non-breaking — no public API removed or changed, only tightened guards, new optional params, and security-floor dependency bumps.

One atomic commit per issue, each with a regression test and a CHANGELOG Security entry.

# Sev Fix
#1021 HIGH FileReadTool/FileWriteTool base_dir sandbox used str.startswith → sibling-dir escape (/ws vs /ws-secret); switched to Path.is_relative_to. Added optional confinement to FileListTool/PDFReaderTool.
#1022 HIGH SSRF in HTTPRequestTool/GraphQLTool/APIBuilderTool (no guard) + WebScraperTool (fail-open) + RSSLoader (file://); all routed through the shared fail-closed loaders/_url_guard, redirects re-validated per hop.
#1023 MED A2AServer bound 0.0.0.0 unauthenticated; added optional auth_token bearer check (constant-time) + warning on public bind without a token.
#1024 HIGH CAG KV-cache .bin fed to llama.cpp's native deserializer with only integrity checks; now HMAC-authenticated (per-install key), dir 0o700, optional CacheKey.namespace. Invalid/tampered blob → cache miss → safe RAG fallback.
#1025 CRIT/HIGH Bumped transformers>=5.10.0 (CVE-2026-9856), snowflake-connector-python>=4.7.1 (CVE-2026-15925), gitpython>=3.1.59 (CVE-2026-78675…78) off known-CVE versions; uv.lock re-locked, OSV audit clean but for the 2 no-fix advisories already risk-accepted.
#1026 LOW CassandraVectorStore interpolated keyspace/table_name into CQL unvalidated; added identifier allowlist (defense-in-depth).

Notes / decisions

  • chromadb (3 advisories) and couchbase (CVE-2023-45875) have no upstream fix; both are server-mode-only / embedded-safe and were already documented and risk-accepted in pyproject.toml. Left as-is.
  • Dependency floors on optional extras only; the lockfile already resolved the same major versions, so the floors codify what shipped rather than widening requirements.
  • A2AServer default host kept at 0.0.0.0 (changing it would be breaking) — the fix warns instead and adds opt-in auth.

Testing

  • New regression tests per fix (path-escape, SSRF via IP-literals/file:// with no network, HMAC tamper-rejection + dir perms, A2A 401/200 over a real loopback socket, CQL identifier rejection).
  • Full touched-area suite green: 1707 passed, 46 skipped.
  • ruff clean; async-blocking gate clean (603 files); post-fix OSV audit clean but for the 2 documented no-fix packages.

Closes #1021, #1022, #1023, #1024, #1025, #1026.

AmitoVrito and others added 7 commits September 8, 2026 19:00
The base_dir sandbox in FileReadTool/FileWriteTool used a raw
str(resolved).startswith(str(base_dir)) check, which a sibling directory
sharing a string prefix (/ws vs /ws-secret) slipped past — allowing an
LLM-supplied path to read and, via FileWriteTool's mkdir(parents=True),
create/overwrite files outside the sandbox. Switch to Path.is_relative_to,
matching the correct precedent in mesh/loaders.py and sandbox/apply.py.

As defense-in-depth, add the same optional base_dir confinement to
FileListTool and PDFReaderTool (previously unconfined). Additive and
non-breaking: default base_dir=None preserves current behavior.

Regression tests cover the sibling-prefix escape, parent traversal, and
in-tree allow paths for read/write/list.

Closes #1021
HTTPRequestTool, GraphQLTool and APIBuilderTool fetched LLM/spec-derived
URLs with no SSRF validation (reachable: 169.254.169.254 metadata,
127.0.0.1, RFC1918, file://). WebScraperTool rolled its own guard that
failed OPEN on DNS errors and only checked the first IPv4 address.
RSSLoader passed unvalidated URLs (incl. file://) straight to feedparser.

Route every fetch through the shared, fail-closed loaders/_url_guard
(scheme allowlist, rejects all private/loopback/link-local addresses,
IPv4-mapped-IPv6 normalized). aiohttp/urllib auto-redirects are now
followed manually so each hop is re-validated; RSSLoader keeps accepting
bare local paths but rejects file:// and other non-http(s) schemes.

Regression tests exercise each site with metadata/loopback/RFC1918/file://
targets using IP literals, so they need no network. Two pre-existing
HTTPRequestTool mock tests were repinned to a public IP literal to stay
hermetic now that the initial URL is validated.

Closes #1022

Co-authored-by: Dhruv Garg <[email protected]>
The POST /a2a endpoint drives executor.run() with no authentication, so
binding it on a network interface (the default host is 0.0.0.0) let any
reachable host drive the agent. Add an optional auth_token: when set,
requests must present a matching Authorization: Bearer <token> header
(constant-time compared via hmac.compare_digest) or get a 401. When the
server binds a non-loopback host without a token, emit a security warning.

Non-breaking: auth_token defaults to None and the default host is
unchanged. run() now stores the HTTPServer on self so it can be shut down.
A real loopback HTTP integration test exercises the 401/200 path over TCP.

Closes #1023
The persisted .bin is a raw llama.cpp state buffer fed straight into a
native C++ deserializer (LlamaState/load_state). KVCacheStore.load only
checked integrity metadata (fingerprint/model/n_ctx) — which an attacker
who can write the cache dir also controls, since they write the .json too.
A crafted blob could reach the native parser: a memory-corruption vector.

- Authenticate every blob with HMAC-SHA256 keyed by a per-install secret
  (auto-generated 0600 key file, or supply KVCacheStore(hmac_key=...)).
  A missing/invalid HMAC is treated as a cache miss, so a tampered or
  foreign blob never reaches load_state; the router rebuilds or uses RAG.
- Create the cache dir 0700 (and chmod an existing one) since it holds
  derived corpus material.
- Add an optional CacheKey.namespace for multi-tenant isolation.

CACHE_FORMAT_VERSION -> 2 invalidates pre-existing unsigned caches, which
are transparently rebuilt. All additive/non-breaking.

Closes #1024

Co-authored-by: Premvkmishra <[email protected]>
CassandraVectorStore interpolates keyspace/table_name into CQL (identifiers
cannot be bound as query parameters) without validation, unlike every
sibling SQL-backed store. Reject anything outside [A-Za-z_][A-Za-z0-9_]* at
construction, closing a latent CQL-injection sink if those names ever become
config-/user-derived. Defense-in-depth: the values are developer-controlled
today, so valid deployments are unaffected.

Closes #1026
…ions

OSV audit of the full resolved graph (549 pkgs, all extras+groups) flagged
three fixable advisories on optional extras:

- transformers >=5.10.0  CVE-2026-9856 save_pretrained path traversal
                         (re-lock 5.9.0 -> 5.16.1)
- snowflake-connector-python >=4.7.1  CVE-2026-15925 TLS hostname bypass
                         (4.5.0 -> 4.7.3)
- gitpython >=3.1.59     CVE-2026-78675/76/77/78 (3.1.58 -> 3.1.62)

The lockfile already resolved these majors, so the floors codify what
shipped and stop a downstream forcing an old vulnerable pin. Post-bump OSV
audit is clean except the two no-fix advisories already risk-accepted
(chromadb embedded-only, couchbase CVE-2023-45875).

Closes #1025
The #1022 SSRF fix routed APIBuilderTool's spec/request fetches through the
validating _open_validated helper instead of urlopen. Repoint the existing
spec-from-URL test's patch target accordingly (example.com passes the guard;
SSRF rejection itself is covered by test_tools_ssrf.py).

Follow-up to #1022

Co-authored-by: Dhruv Garg <[email protected]>
@AmitoVrito AmitoVrito added the security security & trust label Sep 8, 2026
AmitoVrito and others added 3 commits September 8, 2026 19:19
Line-wrapping only (ruff format) on the files touched by #1021–#1026 so the
lint job's `ruff format --check` passes. No behavior change.

Co-authored-by: Premvkmishra <[email protected]>
server_address[0] is typed as possibly bytes, tripping mypy's
str-bytes-safe check in the f-string. Use the known host string for
display and the bound server_address[1] for the port.

Follow-up to #1023
The #1022 SSRF fix replaced web_scraper's bespoke gethostbyname guard with
the shared getaddrinfo-based loaders._url_guard and added a pre-request
guard to GraphQLTool. Update the pre-existing regression tests accordingly:

- web_scraper #570 tests: drive the guard with IP literals instead of
  patching socket.gethostbyname, and invert the old fail-OPEN 'gaierror is
  ignored' test to assert the new fail-CLOSED behavior (the actual bug fix).
- GraphQLTool tests: repoint the mocked endpoint to a public IP literal so
  the guard passes without DNS and the mock/JSON-validation paths still run.

Follow-up to #1022

Co-authored-by: Dhruv Garg <[email protected]>
Co-authored-by: Abhay <[email protected]>
@AmitoVrito
AmitoVrito merged commit e8a4a1d into main Sep 8, 2026
15 checks passed
@AmitoVrito
AmitoVrito deleted the security/hardening-1021-1026 branch September 8, 2026 17:35
Abhay-Mmmm pushed a commit to Abhay-Mmmm/SynapseKit that referenced this pull request Sep 12, 2026
The new issue-889 loaders (graphql, figma, linear, monday, asana, clickup,
shopify, box, zoom) fetched developer-configured endpoints via a shared httpx
client created with follow_redirects=True and no SSRF validation — the exact
fail-open pattern hardened away in SynapseKit#1027 for agents/tools. A trusted-looking
endpoint could 302 to http://169.254.169.254/ (cloud metadata) or 127.0.0.1 and
the client would follow it silently.

http_client now yields a _GuardedHTTPClient wrapper that:
- disables auto-redirects (owned client uses follow_redirects=False) and follows
  redirects manually, re-validating every hop via assert_response_url_public;
- validates the initial URL on the library's own client. An injected client
  keeps its caller-owned request policy, but its redirect hops (server-supplied,
  attacker-influenced) are still validated.

Adds hermetic SSRF regression tests (IP literals, no network) covering private/
metadata/loopback/IPv6 endpoints, non-http schemes, redirect-to-private on an
injected client, allowed public redirects, and the redirect cap.

Co-authored-by: Dhruv Garg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security security & trust

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Path-confinement bypass in file_read/file_write (startswith sibling-dir escape)

1 participant