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

Raise 400 error on duplicate filter parameters #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion medallion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import warnings

from flask import Response, current_app, json
from flask import Response, current_app, json, request
from flask_httpauth import HTTPBasicAuth

from .backends import base as mbe_base
Expand Down Expand Up @@ -156,3 +156,10 @@ def handle_backend_error(error):
status=error.status,
mimetype=MEDIA_TYPE_TAXII_V21,
)


@APPLICATION_INSTANCE.before_request
def validate_match_parameters():
for key, val in request.values.lists():
if len(val) > 1:
raise ProcessingError("The server can not process duplicate request or filter parameters", 400)
8 changes: 8 additions & 0 deletions medallion/test/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,14 @@ def test_object_pagination_changing_params_400(backend):
assert objs["title"] == "ProcessingError"


def test_object_duplicate_match_filter_400(backend):
r = backend.client.get(
test.GET_OBJECTS_EP + "?match[type]=campaign&match[type]=malware",
headers=backend.headers
)
assert r.status_code == 400


# test other config values
# this may warrant some cleanup and organization later
class TestTAXIIWithNoConfig(TaxiiTest):
Expand Down