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

Unhandled exception on invalid filter value for relationship #13

Open
mahenzon opened this issue Apr 23, 2020 · 0 comments
Open

Unhandled exception on invalid filter value for relationship #13

mahenzon opened this issue Apr 23, 2020 · 0 comments
Labels
bug Something isn't working fitering Related to filtering relationships Related to relationships

Comments

@mahenzon
Copy link
Contributor

Here's a vulnerable place:

if value and "links" in value:

For example you have a schema

class UserSchema(Schema):
    class Meta:
        model = User
        type_ = "user"
        self_view = "user_detail"
        self_view_kwargs = {"id": "<id>"}
        self_view_many = "user_list"
        ordered = True

    group = Relationship(
        nested="GroupSchema",
        attribute="_relationship_group_id_",
        related_view="group_detail",
        related_view_kwargs={"id": "<group_id>"},
        schema="GroupSchema",
        type_="group",
    )

And try to filter it using invalid filter:

[
  {
    "name": "group",
    "op": "eq",
    "val": 42
  }
]

It raises this:

  File "/.../src/combojsonapi/combojsonapi/utils/marshmallow_fields.py", line 56, in deserialize
    if value and "links" in value:
TypeError: argument of type 'int' is not iterable

And a valid shorthand for it (which works well) is

[
  {
    "name": "group.id",
    "op": "eq",
    "val": 42
  }
]

I think that this variant has to be working too, but it makes invalid filtering -- returns objects, that should not be here

https://flask-rest-jsonapi.readthedocs.io/en/latest/filtering.html#

[
  {
    "name": "group",
    "op": "any",
    "val": {
      "name": "id",
      "op": "eq",
      "val": 42
    }
  }
]

I think that we have to add proper checks for data and raise InvalidFilters

@mahenzon mahenzon added bug Something isn't working relationships Related to relationships fitering Related to filtering labels Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fitering Related to filtering relationships Related to relationships
Projects
None yet
Development

No branches or pull requests

1 participant