mitre / mitre/HTTP-Proxy-Servlet

URL with encoded ":" or "%" cannot be redirected

Open
#34 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
1.5k
Forks
557
PR merge metrics
No merged PRs in 30d

Description

Hi,
a URL like the following cannot be redirected to the target uri:
http:localhost:8080/mywebapp/myServletPath/%3Asda%25a

The reason is that the ProxyServlet uses servletRequest.getPathInfo() to create the rewriteURL and getPathInfo() returns the decoded path:
/:sda%a

This decoded path is used to create the redirect URL, which leads to an invalid URL in this case. We get an exception like this:

org.apache.http.ProtocolException: Invalid request URI: http:localhost:8080/mywebapp/myServletPath/:sda%a
org.apache.http.impl.client.RequestWrapper.<init>(RequestWrapper.java:83)
org.apache.http.impl.client.EntityEnclosingRequestWrapper.<init>(EntityEnclosingRequestWrapper.java:64)
org.apache.http.impl.client.DefaultRequestDirector.wrapRequest(DefaultRequestDirector.java:328)
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:379)
org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:115)
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
org.mitre.dsmiley.httpproxy.ProxyServlet.service(ProxyServlet.java:245)

Suggestion: Use servletRequest.getRequestURI() instead of servletRequest.getPathInfo() to create the rewriteURL, because servletRequest.getRequestURI() returns the URI not decoded (see also http://stackoverflow.com/questions/966077/java-reading-undecoded-url-from-servlet).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ProxyServlet.java around line 245 and compare how getPathInfo() and getRequestURI() are used to build the rewrite URL. Reproduce the encoded-colon and percent URL from the issue, then verify that the redirected request remains a valid URI without the reported ProtocolException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.