-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Signing Error when sending DELETE request with body to Elasticsearch #1733
Comments
Hi @ajkerr I believe the difference is whether body presents. In your second example, the body will be ignored by the signer, and 'X-Amz-Content-Sha256' header will be used as encoded body. And I don't think it's problem of signing the body because native SDK also uses |
@AllanFly120 Thanks for your response. Ignoring the second example, the big problem for us is that the first example doesn't work for DELETE requests. POSTs, PUTs, etc all seem to work when a body is present, but not DELETEs. |
@AllanFly120 UPDATE: After a lot of tinkering, I noticed that if I add the following line of code to the first request above, the request is sent correctly: request.headers["Content-Length"] = request.body.length; My guess is that the SDK is not setting this header correctly for DELETEs with a body. After digging in the SDK code a bit, I verified that modifying the setHeaders() function as follows in lib/signers/v4.js seems to fix this problem: addHeaders: function addHeaders(credentials, datetime) {
this.request.headers['X-Amz-Date'] = datetime;
if (credentials.sessionToken) {
this.request.headers['x-amz-security-token'] = credentials.sessionToken;
}
if (this.request.body) {
this.request.headers['Content-Length'] = this.request.body.length;
}
}, I notice that the older v2 signer did something similar with this header. |
Hi @ajkerr |
@AllanFly120 Any updates on this? |
@ajkerr I believe the correct solution is to set the If the SDK included a data-plane client for Elasticsearch Service, we would be able to handle this specific case transparently for users. However, SDK internals are being called directly in this case, so the calling code will need to ensure that a |
I did a bit more research to make sure this wasn't a bug and found a justification for the behavior in the HTTP/1.1 spec. Section 4.3 reads in part:
Without either a Content-Length or Transfer-Encoding header, the delimiter that normally signals the end of the headers ( |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
We have run into a strange issue with request signatures when sending DELETE requests to the AWS Elasticsearch service.
Much of the research on this issue came from this issue TheDeveloper/http-aws-es#19 and this AWS forum thread https://forums.aws.amazon.com/thread.jspa?threadID=227353
In this example program, we are attempting to use the Clear Scroll Elasticsearch API (https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-scroll.html#_clear_scroll_api)
In the first request, we are using the flavour of the API where a DELETE request is sent with the scroll_id sent in the body of the request. This request fails with a bad signature error. It shouldn't be failing.
In the second request, we deliberately override the X-Amz-Content-Sha256 header with an incorrect value. This time, the request gets through to Elasticsearch, even though the signature should not be valid. Elasticsearch complains that the scroll_id was not sent.
In the third request, we don't send a request body, and send the scroll id on the request path. This request works correctly (gives the correct error from Elasticsearch).
It's unclear to me whether the AWS v4 signing code in the Javascript SDK is incorrect, or there's something wrong with the signature validation in the Elasticsearch service, but I figured I'd start here.
The text was updated successfully, but these errors were encountered: