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

Add an option to ignore or not the http header "Origin" #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The following is a list of parameters that can be configured
+ log: A boolean parameter name to enable logging of input and target URLs to the servlet log.
+ forwardip: A boolean parameter name to enable forwarding of the client IP
+ preserveHost: A boolean parameter name to keep HOST parameter as-is
+ preserveOrigin: A boolean parameter name to keep Origin parameter as-is
+ preserveCookies: A boolean parameter name to keep COOKIES as-is
+ http.protocol.handle-redirects: A boolean parameter name to have auto-handle redirects
+ http.socket.timeout: A integer parameter name to set the socket connection timeout (millis)
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/mitre/dsmiley/httpproxy/ProxyServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public class ProxyServlet extends HttpServlet {
/** A boolean parameter name to keep HOST parameter as-is */
public static final String P_PRESERVEHOST = "preserveHost";

/** A boolean parameter name to keep Origin parameter as-is */
public static final String P_PRESERVEORIGIN = "preserveOrigin";

/** A boolean parameter name to keep COOKIES as-is */
public static final String P_PRESERVECOOKIES = "preserveCookies";

Expand Down Expand Up @@ -109,13 +112,16 @@ public class ProxyServlet extends HttpServlet {
protected static final String ATTR_TARGET_HOST =
ProxyServlet.class.getSimpleName() + ".targetHost";

public static final String ATTR_HTTP_HEADER_ORIGIN = "Origin";

/* MISC */

protected boolean doLog = false;
protected boolean doForwardIP = true;
/** User agents shouldn't send the url fragment but what if it does? */
protected boolean doSendUrlFragment = true;
protected boolean doPreserveHost = false;
protected boolean doPreserveOrigin = true;
protected boolean doPreserveCookies = false;
protected boolean doHandleRedirects = false;
protected boolean useSystemProperties = true;
Expand Down Expand Up @@ -172,6 +178,11 @@ public void init() throws ServletException {
this.doPreserveHost = Boolean.parseBoolean(preserveHostString);
}

String preserveOriginString = getConfigParam(P_PRESERVEORIGIN);
if (preserveOriginString != null) {
this.doPreserveOrigin = Boolean.parseBoolean(preserveOriginString);
}

String preserveCookiesString = getConfigParam(P_PRESERVECOOKIES);
if (preserveCookiesString != null) {
this.doPreserveCookies = Boolean.parseBoolean(preserveCookiesString);
Expand Down Expand Up @@ -457,6 +468,12 @@ protected void copyRequestHeader(HttpServletRequest servletRequest, HttpRequest
if (hopByHopHeaders.containsHeader(headerName))
return;

// In case the target server does not support CORS,
// just ignore the "Origin" to make the work done.
if(!doPreserveOrigin && ATTR_HTTP_HEADER_ORIGIN.equalsIgnoreCase(headerName)){
return;
}

@SuppressWarnings("unchecked")
Enumeration<String> headers = servletRequest.getHeaders(headerName);
while (headers.hasMoreElements()) {//sometimes more than one value
Expand Down