fix(security): 0.40.3 deferred hardening - out-of-process code, SSRF pinning, MCP scoping#275
Merged
Merged
Conversation
…pinning, MCP scoping Finishes the three deferred items from the 0.40.2 audit sweep. - Code steps run out-of-process by default (CODE_STEPS_OUT_OF_PROCESS): a separate Python subprocess with a secret-free env and POSIX CPU/AS limits, really killed on timeout. Same AST/blocklist/helpers reused in the child. Infra failures fall back to the in-process path. - HTTP steps pin the validated IP at connect time via a custom httpx transport that preserves Host + TLS SNI, closing the DNS-rebind TOCTOU. Mocked and non-resolvable hosts unaffected. - Memory MCP enforces MEMORY_MCP_SCOPE_PREFIX on every tool call; forget requires and validates the owning user_id against the prefix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #273 (0.40.2, merged). Finishes the three harder deferred audit items. Rebased onto main after #273 merged (supersedes the auto-closed #274).
What's in this PR
CODE_STEPS_OUT_OF_PROCESS, default true): a separate Python subprocess with a secret-free env and POSIX CPU/address-space limits, really killed on timeout. Same AST validator, blocklist, and secret-free helpers re-run in the child. Parent validates before spawning; infra failures fall back to in-process.httpx.AsyncHTTPTransportdials the pre-validated IP while preservingHost+ TLS SNI, closing the DNS-rebind TOCTOU. Mocked/non-resolvable hosts unaffected.MEMORY_MCP_SCOPE_PREFIXenforced onadd/search/list_memories/forget;forgetrequires + validates the owninguser_id.CI / testing
test_code_subprocess_runner.py.pr-tests.ymlPython jobtimeout-minutes15 -> 20 (the suite legitimately runs ~13.5 min plus setup; the old gate cancelled a passing run at the 15 min mark).Residual notes (reviewed, acceptable)
CODE_STEPS_OUT_OF_PROCESS=falsefor loop-heavy workloads.forgetvalidates the supplieduser_idis in-prefix but cannot cross-check thememory_idowner (mem0 has no owner-by-id lookup); safe for per-tenant deployments.