-
Notifications
You must be signed in to change notification settings - Fork 2
Add wrapping for clickhouse-driver #392
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6131f0a
Add "clickhouse-driver" as a dev library
bitterpanda63 c1575a7
Revert "Add "clickhouse-driver" as a dev library"
bitterpanda63 b34f6f9
Install clickhouse-driver as a dev dep
bitterpanda63 3ab6645
Still re-lock the flask0clickhouse-uwsgi file
bitterpanda63 745ab24
Add a basic clickhouse_driver sink
bitterpanda63 398f788
Add clickhouse to the map of dialects
bitterpanda63 85dc2b1
Add unit tests for clickhouse driver
bitterpanda63 aa3366d
Also add tests for cursor
bitterpanda63 49eeb19
Add clickhouse-driver to readme
bitterpanda63 238a6d5
Add wrapping for execute_iter and execute_with_progress
bitterpanda63 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from aikido_zen.helpers.get_argument import get_argument | ||
from aikido_zen.sinks import before, on_import, patch_function | ||
from aikido_zen.vulnerabilities import run_vulnerability_scan | ||
|
||
|
||
@before | ||
def _execute(func, instance, args, kwargs): | ||
kind = "sql_injection" | ||
op = "clickhouse_driver.Client.execute" | ||
query = get_argument(args, kwargs, 0, "query") | ||
run_vulnerability_scan(kind, op, args=(query, "clickhouse")) | ||
|
||
|
||
@on_import("clickhouse_driver", package="clickhouse_driver") | ||
def patch(m): | ||
""" | ||
patching module clickhouse_driver | ||
- patches clickhouse_driver.Client.execute | ||
- patches clickhouse_driver.Client.execute_iter | ||
- patches clickhouse_driver.Client.execute_with_progress | ||
""" | ||
patch_function(m, "Client.execute", _execute) | ||
patch_function(m, "Client.execute_iter", _execute) | ||
patch_function(m, "Client.execute_with_progress", _execute) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import aikido_zen.sinks.clickhouse_driver | ||
import pytest | ||
from aikido_zen.background_process import reset_comms | ||
from aikido_zen.context import Context | ||
from aikido_zen.errors import AikidoSQLInjection | ||
|
||
|
||
class Context1(Context): | ||
def __init__(self, body): | ||
self.cookies = {} | ||
self.headers = {} | ||
self.remote_address = "1.1.1.1" | ||
self.method = "POST" | ||
self.url = "url" | ||
self.query = {} | ||
self.body = body | ||
self.source = "express" | ||
bitterpanda63 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.route = "/" | ||
self.parsed_userinput = {} | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def set_blocking_to_true(monkeypatch): | ||
monkeypatch.setenv("AIKIDO_BLOCK", "1") | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
from clickhouse_driver import Client | ||
|
||
return Client( | ||
host="127.0.0.1", port=9000, user="default", password="", database="default" | ||
) | ||
|
||
|
||
def test_client_execute_without_context(client): | ||
reset_comms() | ||
dog_name = "Steve" | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
client.execute(sql) | ||
|
||
|
||
def test_client_execute_safe(client): | ||
reset_comms() | ||
dog_name = "Steve" | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
Context1({"dog_name": dog_name}).set_as_current_context() | ||
client.execute(sql) | ||
|
||
|
||
def test_client_execute_unsafe(client, monkeypatch): | ||
reset_comms() | ||
dog_name = "Malicious dog', 1); -- " | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
Context1({"dog_name": dog_name}).set_as_current_context() | ||
|
||
with pytest.raises(AikidoSQLInjection): | ||
client.execute(sql) | ||
|
||
monkeypatch.setenv("AIKIDO_BLOCK", "0") | ||
client.execute(sql) | ||
|
||
|
||
def test_cursor_execute_safe(): | ||
from clickhouse_driver import connect | ||
|
||
conn = connect("clickhouse://localhost:9000") | ||
reset_comms() | ||
dog_name = "Steve" | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
Context1({"dog_name": dog_name}).set_as_current_context() | ||
conn.cursor().execute(sql) | ||
|
||
|
||
def test_cursor_execute_unsafe(monkeypatch): | ||
from clickhouse_driver import connect | ||
|
||
conn = connect("clickhouse://localhost:9000") | ||
reset_comms() | ||
dog_name = "Malicious dog', 1); -- " | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
Context1({"dog_name": dog_name}).set_as_current_context() | ||
|
||
with pytest.raises(AikidoSQLInjection): | ||
conn.cursor().execute(sql) | ||
|
||
monkeypatch.setenv("AIKIDO_BLOCK", "0") | ||
conn.cursor().execute(sql) | ||
|
||
|
||
def test_client_execute_with_progress_safe(client): | ||
reset_comms() | ||
dog_name = "Steve" | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
Context1({"dog_name": dog_name}).set_as_current_context() | ||
client.execute_with_progress(sql) | ||
|
||
|
||
def test_client_execute_with_progress_unsafe(client, monkeypatch): | ||
reset_comms() | ||
dog_name = "Malicious dog', 1); -- " | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
Context1({"dog_name": dog_name}).set_as_current_context() | ||
|
||
with pytest.raises(AikidoSQLInjection): | ||
client.execute_with_progress(sql) | ||
|
||
monkeypatch.setenv("AIKIDO_BLOCK", "0") | ||
client.execute_with_progress(sql) | ||
|
||
|
||
def test_client_execute_iter_safe(client): | ||
reset_comms() | ||
dog_name = "Steve" | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
Context1({"dog_name": dog_name}).set_as_current_context() | ||
client.execute_iter(sql) | ||
|
||
|
||
def test_client_execute_iter_unsafe(client, monkeypatch): | ||
reset_comms() | ||
dog_name = "Malicious dog', 1); -- " | ||
sql = "INSERT INTO dogs (dog_name, isAdmin) VALUES ('{}' , 0)".format(dog_name) | ||
Context1({"dog_name": dog_name}).set_as_current_context() | ||
|
||
with pytest.raises(AikidoSQLInjection): | ||
client.execute_iter(sql) | ||
|
||
monkeypatch.setenv("AIKIDO_BLOCK", "0") | ||
client.execute_iter(sql) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
DIALECTS = { | ||
"generic": 0, | ||
"clickhouse": 3, | ||
"mysql": 8, | ||
"postgres": 9, | ||
"sqlite": 12, | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.