Moving this conversation out of a Fixed and committed issue. Backscroll here: https://www.drupal.org/project/jsonapi/issues/2933062#comment-12672812
Gist: It may be impractical for consumers to issue only HTTP requests with specification-compliant query parameters. These query parameters are often required by layers of the HTTP stack beyond this module's control.
Should we ignore these violations of the spec, in violation of the spec? If so, how?
- We could simply not enforce it.
- We could let certain parameters be whitelisted.
- Or, we could leave it up to .htaccess/nginx.conf/custom/contrib code.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2984044-q-param-16.patch | 371 bytes | tom friedhof |
| #13 | 2984044-include-q-reserved-param.patch | 371 bytes | angheloko |
| #12 | json_api_q_param.patch | 593 bytes | kmezu |
Comments
Comment #2
gabesullicePersonally, I think there are suitable ways for this module to remain specification compliant that truly aren't so burdensome.
I'd rather provide a helpful link in the 400 error that points people in the right direction instead of carving out special behavior that has BC implications.
IOW, I think this feels like an upstream bug in the spec that could be worked around without making our implementation more of a snowflake.
Comment #3
e0ipsoThe Robustness principle recommends that we are very strict with what the JSON API module outputs, and liberal in what inputs we accept. In particular:
I didn't know this had a name, but this gut feeling @Wim Leers, @gdd and myself had is apparently a very real thing.
I am leaning towards option #1: We could simply not enforce it.
Comment #4
wim leersThanks @gabesullice for doing what @e0ipso and I should already have done: open a new issue and discuss there.
#2933062-45: [>=8.5.4] Spec Compliance: Return 400 for unrecognized/unsupported query parameters:
I'm not a fan of having to install another module that strips out disallowed parameters, because that then means extra things to figure out and configure: developers have to know about this extra module, and configure it just the right way to strip just the right query parameters.
#2933062-46: [>=8.5.4] Spec Compliance: Return 400 for unrecognized/unsupported query parameters:
That'd mean it would not be
?filter=, but?jsonapi_filter=or?_filter=. So I totally get why they're being so broad; for the sake of DX of JSON API users.#3: I'm familiar with the robustness principle — I pointed to it many times, including in the docblock of
\Drupal\rest\EventSubscriber\ResourceResponseSubscriber::getResponseFormat():)I thought about this some more. I am very tempted to apply the robustness principle in a tentative way:
Because it seems that the most common scenario for having additional URL query parameters is proxies/CDNs that do certain things based on those query parameters. But … those proxies/CDNs should then also remove that query parameter when the request is forwarded to the origin (the Drupal site with JSON API). They should already be doing that. And if they are… then there is no problem! :D
The only non-proxy/CDN example given at #2933062-42: [>=8.5.4] Spec Compliance: Return 400 for unrecognized/unsupported query parameters is
?preview. But this is custom code in a Drupal module. So that module could quite easily be updated with a middleware to map the one (or few) specific query parameters it reacts to, to parameter names that are allowed by the JSON API spec. Then clients would not need to be updated.In other words:
Thoughts?
Comment #5
e0ipsoThat forces people to speak up and fight against the current status. That's something the vast majority of people won't do.
In any case I won't fight this either. I think it's a mistake, but admittedly it won't have a huge impact.
Comment #6
wim leersI don't think people are afraid to file bug reports? (They'll perceive this as a bug.)
Comment #7
wim leersOnly the 3 of us are following this issue. Zero bug reports even remotely related to this in nearly 5 months and 3 weeks. I think it's safe to say this is unneeded :) And we can reopen it if that need does exist in the future!
Comment #8
bgm commentedI ran into the following issue, after doing a security update to the latest version:
"The following query parameters violate the JSON:API spec: 'q'."
and it ended up being a silly nginx configuration error: it was using the old Drupal6 rewrite on the index.php, instead of the one for Drupal7/Drupal8 (well, an incorrect Aegir config was kicking in..).
Comment #9
gmarineau commentedHi I have the same issue : #8
Can you give me the config for nginx ?
Comment #10
bgm commenteduse:
rewrite ^ /index.php?$query_string last;instead of
rewrite ^/(.*)$ /index.php?q=$1 last;(but you may want to double-check with the various howtos/guides out there)
Comment #11
shadcn commentedNote: if you're using Laravel Valet and seeing this bug. There's a PR in review here: https://github.com/laravel/valet/pull/705
Comment #12
kmezu commentedHey there, this issue actually came up recently within my internship project. Theres a quick patch you can perform on the JsonApiSpec.php to simply ignore the q parameter! Please try it out for yourself, thanks!
Comment #13
angheloko commentedPatch for Drupal 9.2
Comment #14
juancarielo commentedWorks adding the "q": #13
I'm using Drupal version 9.3.6.
Thank you @angheloko
Comment #15
taggartj commentedwell its kinda like this ... modules that are very opinionated and don't let people do what they need is kinda crap
so this leads to hackery like the following.
Comment #16
tom friedhof commentedRerolling #12