-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stable/v3' into merge_stable_240702
- Loading branch information
Showing
7 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,63 @@ | ||
import pytest | ||
import weaviate | ||
import requests | ||
import json | ||
|
||
|
||
def injection_template(n: int) -> str: | ||
return "Liver" + ("\\" * n) + '"}}){{answer}}}}{payload}#' | ||
|
||
|
||
@pytest.mark.parametrize("n_backslashes", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | ||
def test_gql_injection(n_backslashes: int) -> None: | ||
client = weaviate.Client(url="http://localhost:8080") | ||
client.schema.delete_class("Question") | ||
client.schema.delete_class("Hacked") | ||
class_obj = { | ||
"class": "Question", | ||
"vectorizer": "text2vec-contextionary", | ||
"properties": [ | ||
{"name": "answer", "dataType": ["string"], "tokenization": "field"}, | ||
{"name": "question", "dataType": ["string"]}, | ||
{"name": "category", "dataType": ["string"]}, | ||
], | ||
} | ||
|
||
class_obj2 = { | ||
"class": "Hacked", | ||
"vectorizer": "text2vec-contextionary", | ||
"properties": [ | ||
{"name": "answer", "dataType": ["string"]}, | ||
{"name": "question", "dataType": ["string"]}, | ||
{"name": "category", "dataType": ["string"]}, | ||
], | ||
} | ||
client.schema.create_class(class_obj) | ||
client.schema.create_class(class_obj2) | ||
|
||
resp = requests.get( | ||
"https://raw.githubusercontent.com/weaviate-tutorials/quickstart/main/data/jeopardy_tiny.json" | ||
) | ||
data = json.loads(resp.text) | ||
|
||
client.batch.configure(batch_size=100) | ||
with client.batch as batch: | ||
for _, d in enumerate(data): | ||
properties = { | ||
"answer": d["Answer"], | ||
"question": d["Question"], | ||
"category": d["Category"], | ||
} | ||
batch.add_data_object(data_object=properties, class_name="Question") | ||
batch.add_data_object(data_object=properties, class_name="Hacked") | ||
|
||
injection_payload = client.query.get("Hacked", ["answer"]).build() | ||
query = client.query.get("Question", ["question", "answer", "category"]).with_where( | ||
{ | ||
"path": ["answer"], | ||
"operator": "NotEqual", | ||
"valueText": injection_template(n_backslashes).format(payload=injection_payload[1:]), | ||
} | ||
) | ||
res = query.do() | ||
assert "Hacked" not in res["data"]["Get"] |
This file contains 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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
python3 -m venv venv | ||
source venv/bin/activate | ||
pip install -r requirements-devel.txt >/dev/null 2>&1 | ||
|
||
echo "Static checking ./weaviate:" | ||
mypy --config-file ./pyproject.toml ./weaviate | ||
echo "Static checking ./integration:" | ||
mypy --config-file ./pyproject.toml ./integration | ||
mypy --config-file ./pyproject.toml --warn-unused-ignores ./weaviate |
This file contains 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 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