Open AdrienLemaire opened 5 years ago
Quick and dirty temporary fix in my project until this issue is resolved:
class StrictIndexView(IndexView):
def get_filters(self, request: HttpRequest) -> tuple:
"""
Override get_filters to remove sendgrid filters
"""
(
self.filter_specs,
self.has_filters,
remaining_lookup_params,
filters_use_distinct,
) = super().get_filters(request)
remaining_lookup_params = {
k: v
for k, v in remaining_lookup_params.items()
if not k.startswith("utm")
}
return (
self.filter_specs,
self.has_filters,
remaining_lookup_params,
filters_use_distinct,
)
class MyModelAdmin(ModelAdmin):
model = MyModel
index_view_class = StrictIndexView
ModelAdmin is only intended to be used within the Wagtail admin, and so I wouldn't class this as a bug necessarily. Users shouldn't be adding random query params to URLs either - for every view in wagtail to safely ignore all user-added GET parameters would be a reasonable chunk of work, and something I don't think we'd want to make promises about going forward.
That said, I would be happy to review a pull request that implemented a change along these lines, so long as there wasn't a significant affect on performance. @AdrienLemaire would you be up for creating a PR?
Found a bug? Please fill out the sections below. 👍
Issue Summary
When accessible a url from a third-part service, unwanted get keywords may be appended to the url, eg:
/?utm_campaign=website&utm_source=sendgrid.com&utm_medium=email
The currently logic of
modeladmin.views.IndexView
is to filtered out IGNORED_PARAMS (order, order_type, search vars) then send all remaining filters to the queryset.wagtail/contrib/modeladmin/views.py
Steps to Reproduce
class MyModelAdmin(ModelAdmin):
)/?a=1
and refresh.Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?
I would have expected a whitelist of authorized filters instead, or a way to ignore incorrect params. The system shouldn't break when a user add unexpected get params to the url.
Technical details