Fix Neo4j Cypher injection in BaseBot.write_to_graph#58
Merged
Conversation
property_name was built from self.name via an f-string and interpolated directly into the Cypher query (Neo4j has no parameterized syntax for property names, only values), so a bot name containing Cypher metacharacters could break out of the intended `s.<property>` position and run arbitrary graph operations. Validate property_name against a strict identifier allowlist (^[a-z][a-z0-9_]*$) before it's used in the query, and raise instead of running the query if it doesn't match. All current bot names (runway, pmf, pivot, etc.) match this pattern already. Fixes #35 Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
property_namewas built fromself.namevia an f-string and interpolated directly into the Cypher query text (Neo4j has no parameterized syntax for property names, only values), so a bot name containing Cypher metacharacters (backticks, braces, semicolons, etc.) could break out of the intendeds.<property>position and run arbitrary graph operations.runway,pmf,pivot,term,obituary,investor,acqui,accelerator) are hardcoded lowercase words, so this isn't exploitable today, but nothing enforced that invariant — this closes the gap defensively.^[a-z][a-z0-9_]*$) thatproperty_namemust match before it's used in the query; raisesValueErrorinstead of running the query if it doesn't.Test plan
pytest tests/test_bots -q— 28 passed (includes 8 new tests forwrite_to_graph).neo4jisn't configured, and rejection of several Cypher-injection payloads (backtick/brace breakout, semicolon, embedded space, uppercase, empty string) with no query executed.ruff checkpasses on changed files.pytest tests -qhas 37 pre-existing failures unrelated to this change (they require a live Postgres connection unavailable in this sandbox); all other tests (175) pass.Fixes #35
Made with Cursor