[CXF-8535] Query missing from signature request-target AND also to add digest only if request has body#869
Conversation
…d digest only if request has body
|
@coheigea PTAL |
...y/http-signature/src/main/java/org/apache/cxf/rs/security/httpsignature/MessageVerifier.java
Outdated
Show resolved
Hide resolved
| private static final String METHOD = "GET"; | ||
| private static final String URI = "/test/signature"; | ||
| private static final String KEY_PAIR_GENERATOR_ALGORITHM = "RSA"; | ||
| private static final String MESSAGE_BODY = "Hello"; |
There was a problem hiding this comment.
@AnilKumarHurkadli I just realized there are no testcases for the case when message body is not present, exactly the flow you are implementing. Could you please add a couple please?
There was a problem hiding this comment.
@reta Sure will add the test case for which InvalidDataToVerifySignatureException will not be thrown if the body is null and passes fine. The issue was encountered specifically while testing DELETE method which "usually" do not have body and "Digest" header gets added by default in the required headers and is NOT removed as it was not satisfying below condition
if ((requestor && (status < 200 || status >= 300 || status == 204))
|| (!requestor && ("GET".equalsIgnoreCase(method) || "HEAD".equalsIgnoreCase(method)))) {
signedHeaders.remove("digest");
}
And was throwing InvalidDataToVerifySignatureException with message "Not all of the required headers are signed"
There was a problem hiding this comment.
@reta Have incorporated the test case described in the conversation above
There was a problem hiding this comment.
@reta Path parameters were being decoded while verifying the signatures and hence there were mismatch in the request-target , have provided fix to avoid decoding of the path parameters by using rawpath instead of path
There was a problem hiding this comment.
@AnilKumarHurkadli thank you, makes sense to me: it is unclear why previously the uri.getPath() was combined with uri.getRawQuery(), either getPath() + getQuery() or getRawPath() + getRawQuery() should have been followed (imho), thank you for fixing.
There was a problem hiding this comment.
@reta Thank you for reviewing the changes , yes rawpath and rawquery works well as it does not decodes and retains as is for verification.
|
@coheigea from the implementation perspective - LGTM, but from the spec perspective would be great to hear your opinion, thank you. |
… of path otherwise will result in invalid signatures
|
The changes look fine to me, but it is causing a test failure in systests/rs-security (JAXRSHTTPSignatureTest) can you take a look? |
Sure @coheigea will take a look why that particular case is failing and update accordingly |
@test URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); CreateSignatureInterceptor signatureFilter = new CreateSignatureInterceptor(); List headerList = Arrays.asList("accept", "(request-target)"); String address = "http://localhost:" + PORT + "/httpsigprops/bookstore/books"; Response response = client.post(new Book("CXF", 126L)); OR to have additional check to add digest in the required headers for POST or PUT method in the below condition in MessageVerifier? From , |
|
I think the test-case is valid, so please instead consider adding POST/PUT as you suggested above. |
…d digest only if request has body (#869) * [CXF-8535] Query missing from signature request-target AND also to add digest only if request has body * Message body available in Filter is used and added as an argument which is passed through * Added Test case for not throwing exception having null body Delete Method * Fix to avoid decoding of the path parameters by using rawpath instead of path otherwise will result in invalid signatures * Fixing the test case failure in systests/rs-security by adding required conditions in MessageVerifier Co-authored-by: Anilkumar Hurkadli <Anilkumar.Hurkadli@evryindia.in>
[CXF-8535] Query missing from signature request-target AND also to add digest only if request has body AND Fix to avoid decoding of the path parameters
The following fixes are incorporated in this PR
The issue was instead of using getRequestUri of URI info to consider the query parameters in the request-target , getAbsolutePath was used which truncates the query parameters in VerifySignatureFilter and results in Invalid Signature while verifying.
In addition to that, digest will be added to the required headers only if the request has payload/body.
Test cases are also been incorporated for the above fix