-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jami Cogswell
authored and
Jami Cogswell
committed
Dec 1, 2023
1 parent
62bd01f
commit 5773be6
Showing
6 changed files
with
25 additions
and
132 deletions.
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
java/ql/src/Security/CWE/CWE-552/UnsafeLoadSpringResource.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
java/ql/src/Security/CWE/CWE-552/UnsafeServletRequestDispatch.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,17 @@ | ||
import java.io.IOException; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.servlet.ModelAndView; | ||
public class UrlForward extends HttpServlet { | ||
private static final String VALID_FORWARD = "https://cwe.mitre.org/data/definitions/552.html"; | ||
|
||
@Controller | ||
public class UrlForward { | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
ServletConfig cfg = getServletConfig(); | ||
ServletContext sc = cfg.getServletContext(); | ||
|
||
@GetMapping("/bad1") | ||
public ModelAndView bad1(String url) { | ||
return new ModelAndView(url); | ||
} | ||
|
||
@GetMapping("/bad2") | ||
public void bad2(String url, HttpServletRequest request, HttpServletResponse response) { | ||
try { | ||
request.getRequestDispatcher("/WEB-INF/jsp/" + url + ".jsp").include(request, response); | ||
} catch (ServletException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
// BAD: a request parameter is incorporated without validation into a URL forward | ||
sc.getRequestDispatcher(request.getParameter("target")).forward(request, response); | ||
|
||
@GetMapping("/good1") | ||
public void good1(String url, HttpServletRequest request, HttpServletResponse response) { | ||
try { | ||
request.getRequestDispatcher("/index.jsp?token=" + url).forward(request, response); | ||
} catch (ServletException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
// GOOD: the request parameter is validated against a known fixed string | ||
if (VALID_FORWARD.equals(request.getParameter("target"))) { | ||
sc.getRequestDispatcher(VALID_FORWARD).forward(request, response); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters