Skip to content

Commit

Permalink
XIVY-15609 Improve path encoding for signing request
Browse files Browse the repository at this point in the history
Using UrlEncoder which is not especially designed for this.
It's hard to find out, how the calling end url is, because
this relies on the underlying technology jersey -> connectory
-> apache http connector. Tried a lot of stuff and this implementation
was the best. It specially handles the characters which are also
specially handled in UrlEncoder.

The main problem is that we should not allow to create such documents.
We should difference between a display name and a technical file name.
  • Loading branch information
alexsuter committed Dec 6, 2024
1 parent b86884e commit 51c867c
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import static com.axonivy.connector.aws.authentication.Constants.SIGNED_HEADERS;
import static com.axonivy.connector.aws.authentication.Constants.X_AMZ_DATE;

import java.net.URI;
import java.net.URISyntaxException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import javax.ws.rs.client.ClientRequestContext;

Expand Down Expand Up @@ -41,13 +42,16 @@ private void appendPath() {
if (path == null || path.isEmpty()) {
path = "/";
}

try {
var encodedPath = new URI(null, null, path, null).toASCIIString();
var encodedPath = URLEncoder.encode(path, StandardCharsets.UTF_8.toString())
.replace("%2F", "/")
.replace("%7E", "~")
.replace("*", "%2A")
.replace("+", "%20");
builder.append(encodedPath);
builder.append('\n');
} catch (URISyntaxException ex) {
throw new RuntimeException(ex);
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException("Unable to encode path " + path, ex);
}
}

Expand Down

0 comments on commit 51c867c

Please sign in to comment.