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

CMS-7860 - Disallow any access to the contents of WEB-INF from client… #128

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private ParamError validateParameter(String key, String value)
}
catch (PatternSyntaxException e)
{
log.error("Invalid Regular Expression, skipping restriction: " + ptn);
log.error("Invalid Regular Expression, skipping restriction: {}" , ptn);
continue;
}
}
Expand Down
16 changes: 15 additions & 1 deletion system/src/com/percussion/servlets/PSDispatcherFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.*;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
Expand All @@ -48,6 +53,10 @@ public class PSDispatcherFilter implements Filter {

private static final Pattern pattern = Pattern.compile("^.+\\/\\/[^\\/]+\\/Sites\\/([^\\/]*)", Pattern.MULTILINE);

private static final String[] bannedPaths = new String[]{
"/WEB-INF/"
};

private static final String[] resourcePaths = new String[] {
"/Sites/",
"/Assets/",
Expand Down Expand Up @@ -104,6 +113,11 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
String strippedPath = path.startsWith(RHYTHMYX) ? StringUtils.substringAfter(path,RHYTHMYX) : path;
String newPath = path;

if(Stream.of(bannedPaths).anyMatch(strippedPath::contains)){
((HttpServletResponse) response).setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}

if (Stream.of(resourcePaths).anyMatch(strippedPath::startsWith))
{
newPath = strippedPath;
Expand Down
14 changes: 7 additions & 7 deletions system/src/com/percussion/servlets/PSSetCommunityFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import com.percussion.utils.request.PSRequestInfo;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
Expand All @@ -52,7 +52,7 @@

public class PSSetCommunityFilter implements Filter
{
private static final Log log = LogFactory.getLog(PSSetCommunityFilter.class);
private static final Logger log = LogManager.getLogger(PSSetCommunityFilter.class);

/**
* Filter the request, if the session of the request has been authenticated,
Expand Down Expand Up @@ -101,7 +101,7 @@ private void setCommunityIfNeeded(ServletRequest request,
{
PSRequestInfo.initRequestInfo(httpReq);
needsReset = true;
log.info("Need to reset Request ID: " + httpReq.getRemoteUser());
log.info("Need to reset Request ID: {}", httpReq.getRemoteUser());
}

PSRequest psReq = initRequest(httpReq, httpResp);
Expand All @@ -118,8 +118,7 @@ private void setCommunityIfNeeded(ServletRequest request,
PSAuthenticateUserUtils.SYS_DEFAULTCOMMUNITY);
if (StringUtils.isBlank(communityName))
{
log.debug("Cannot find a default community for user: \""
+ reqCtx.getUserName() + "\"");
log.debug("Cannot find a default community for user: {}", reqCtx.getUserName());
return; // do nothing if cannot find default community.
}

Expand All @@ -142,8 +141,9 @@ private void setCommunityIfNeeded(ServletRequest request,
}
finally
{
if (needsReset)
if (needsReset) {
PSRequestInfo.resetRequestInfo();
}
}
}

Expand Down