Skip to content

Commit

Permalink
Merge pull request #128 from percussion/CMS-7860
Browse files Browse the repository at this point in the history
CMS-7860 - Disallow any access to the contents of WEB-INF from client…
  • Loading branch information
sonydeswal74 committed May 14, 2021
2 parents 45f3d9a + e2b4ab1 commit b1b2646
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
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

0 comments on commit b1b2646

Please sign in to comment.