Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Fix: Updating graph parser for potential injection cases #2548

Merged
merged 4 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Fix string cleanse in Redis Graph
* Make PythonParser resumable in case of error (#2510)
* Add `timeout=None` in `SentinelConnectionManager.read_response`
* Documentation fix: password protected socket connection (#2374)
Expand Down
1 change: 1 addition & 0 deletions redis/commands/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def quote_string(v):
if len(v) == 0:
return '""'

v = v.replace("\\", "\\\\")
v = v.replace('"', '\\"')

return f'"{v}"'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_path(client):

@pytest.mark.redismod
def test_param(client):
params = [1, 2.3, "str", True, False, None, [0, 1, 2]]
params = [1, 2.3, "str", True, False, None, [0, 1, 2], r"\" RETURN 1337 //"]
query = "RETURN $param"
for param in params:
result = client.graph().query(query, {"param": param})
Expand Down
6 changes: 6 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ def test_quote_string():
assert quote_string("hello world!") == '"hello world!"'
assert quote_string("") == '""'
assert quote_string("hello world!") == '"hello world!"'
assert quote_string("abc") == '"abc"'
assert quote_string("") == '""'
assert quote_string('"') == r'"\""'
assert quote_string(r"foo \ bar") == r'"foo \\ bar"'
assert quote_string(r"foo \" bar") == r'"foo \\\" bar"'
assert quote_string('a"a') == r'"a\"a"'