You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@roller.apache.org by GitBox <gi...@apache.org> on 2021/06/06 14:26:17 UTC

[GitHub] [roller] mbien commented on a change in pull request #84: Improve input validation

mbien commented on a change in pull request #84:
URL: https://github.com/apache/roller/pull/84#discussion_r646140410



##########
File path: app/src/main/java/org/apache/roller/weblogger/webservices/tagdata/TagDataServlet.java
##########
@@ -70,36 +72,56 @@ public void doGet(
             HttpServletRequest request, HttpServletResponse response) 
             throws ServletException, IOException {
 
-        String[] pathInfo = new String[0];
-        boolean siteWide;
-        String handle;
-        String prefix;
-        String format = "json";
-        int page = 0;
-        
         // TODO: last modified or ETag support, caching, etc.
 
+        String[] pathInfo = new String[0];
+        
         if (request.getPathInfo() != null) {
             pathInfo = Utilities.stringToStringArray(request.getPathInfo(),"/");
         }
+        
+        boolean siteWide;
+        String handle;
+
         if (pathInfo.length == 0) {
             siteWide = true;
             // we'll use the front-page weblog to form URLs
             handle = WebloggerRuntimeConfig.getProperty("site.frontpage.weblog.handle");
-        } else if (pathInfo.length == 2 && "weblog".equals(pathInfo[0])) {
+        } else if (pathInfo.length == 2 && "weblog".equals(pathInfo[0]) && StringUtils.isAlphanumeric(pathInfo[1])) {
             siteWide = false;
             handle = pathInfo[1];
         } else {
             response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Malformed URL");
             return;
         }
-        prefix = request.getParameter("prefix");
+
+        String prefix = request.getParameter("prefix");
+
+        if(prefix != null && !StringUtils.isAlphanumeric(prefix)) {
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Malformed URL");
+            return;
+        }
+        
+        String format = "json";  // default
+        
         if (request.getParameter("format") != null) {
+            
             format = request.getParameter("format");
+            if(!format.equals("json") || !format.equals("xml")) {
+                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Malformed URL");
+                return;

Review comment:
       todo: this should be && not ||




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org