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

@QueryParameter trashes the request body #416

Open
jtnord opened this issue Nov 4, 2022 · 2 comments
Open

@QueryParameter trashes the request body #416

jtnord opened this issue Nov 4, 2022 · 2 comments
Labels

Comments

@jtnord
Copy link
Member

jtnord commented Nov 4, 2022

Jenkins and plugins versions report

QueryParameter is only supposed to look at the HTTP query but looks also in the RequestBody making it unusable for others
Paste the output here

What Operating System are you using (both controller, and any agents involved in the problem)?

windows java11

Reproduction steps

  1. create a method as follows from something accessable from stapler as
public void doFoo(@QueryParameter(required = false) String payload, StaplerRequest request, StaplerResponse response) throws IOException {
   String body = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding());
   System.out.print(body);
}

call the endpoint with curl curl theEddpoint --data blahblahblah

Expected Results

blahblahblah is printed

Actual Results

the string is enmpty

Anything else?

because the query parameter is optional it is not in the URL.

QueryParameter calls request.getParameter(name) which is eventually ServletRequest.getParameter(String)

This code is what will then read the body to find an populate the parameters - meaning the reading of the body later will fail (as it is read the available length of it will be zero)

e.g. for Jetty for example ->
https://github.com/eclipse/jetty.project/blob/bff5b3eb8f5547afd8883029555dd46d06ed7a77/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java#L1046-L1050

This is in violation of the contract of the QueryParameter

@jtnord jtnord added the bug label Nov 4, 2022
@jtnord
Copy link
Member Author

jtnord commented Nov 4, 2022

Note: that in the case of Jetty it first checks the content-type and only does it if the content-type if form encoding or multipart data.

@timja
Copy link
Member

timja commented Nov 4, 2022

Seems to be a limitation of servlet spec, workarounds here:
https://stackoverflow.com/a/31928740

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants