Conversation
| response.setContentType("text/html"); | ||
| PrintWriter out = response.getWriter(); | ||
| out.print("<h2>Hello "+name+ "</h2>"); | ||
| out.print("<h2>Hello " + escapedName + "</h2>"); |
Check failure
Code scanning / SonarQube
Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks
|
|
||
| // Add request validation | ||
| if (request.getContentLength() > 1024) { | ||
| response.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
|
|
||
| // Add input validation | ||
| if (user == null || user.trim().isEmpty()) { | ||
| response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Username parameter is required"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
| } | ||
|
|
||
| if (user.length() > MAX_USERNAME_LENGTH) { | ||
| response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Username too long"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
| throw new RuntimeException(e); | ||
| // Log the error instead of throwing RuntimeException | ||
| System.err.println("Error retrieving users: " + e.getMessage()); | ||
| response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
| SessionHeader sessionHeader = getSessionHeader(request); | ||
| if (sessionHeader == null) return; | ||
| if (sessionHeader == null) { | ||
| response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid session"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
|
|
||
| String user = sessionHeader.getUsername(); | ||
| if (user == null || user.trim().isEmpty()) { | ||
| response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid username in session"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
| throw new RuntimeException(e); | ||
| // Log the error instead of throwing RuntimeException | ||
| System.err.println("Error retrieving users: " + e.getMessage()); | ||
| response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
|
| response.setContentType("text/html"); | ||
| PrintWriter out = response.getWriter(); | ||
| out.print("<h2>Hello "+name+ "</h2>"); | ||
| out.print("<h2>Hello " + escapedName + "</h2>"); |
Check failure
Code scanning / SonarQube
Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks
|
|
||
| // Add request validation | ||
| if (request.getContentLength() > 1024) { | ||
| response.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
|
|
||
| // Add input validation | ||
| if (user == null || user.trim().isEmpty()) { | ||
| response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Username parameter is required"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
| } | ||
|
|
||
| if (user.length() > MAX_USERNAME_LENGTH) { | ||
| response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Username too long"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
| throw new RuntimeException(e); | ||
| // Log the error instead of throwing RuntimeException | ||
| System.err.println("Error retrieving users: " + e.getMessage()); | ||
| response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
| SessionHeader sessionHeader = getSessionHeader(request); | ||
| if (sessionHeader == null) return; | ||
| if (sessionHeader == null) { | ||
| response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid session"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
|
|
||
| String user = sessionHeader.getUsername(); | ||
| if (user == null || user.trim().isEmpty()) { | ||
| response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid username in session"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
| throw new RuntimeException(e); | ||
| // Log the error instead of throwing RuntimeException | ||
| System.err.println("Error retrieving users: " + e.getMessage()); | ||
| response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error"); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods
- Add SQL injection vulnerabilities with taint analysis examples - Include XSS vulnerabilities with unescaped user input - Add path traversal and command injection issues - Include security hotspots (hardcoded passwords, weak crypto) - Add code quality issues (dead code, duplicated code, magic numbers) - Create complex data flow examples for taint analysis demos - Add deserialization vulnerabilities and information disclosure - Include performance issues and code smells - Update README with comprehensive demo guide for sales engineers Perfect for demonstrating SonarQube's comprehensive analysis capabilities including taint analysis, security hotspots, and code quality metrics.
ecdd7f2 to
50a3f5a
Compare
- Remove all SonarQube issue comments from servlet files - Simplify README to basic usage instructions - Keep vulnerabilities intact for demo purposes - Clean up code for better readability
Co-authored-by: Cursor <cursoragent@cursor.com>




These changes address common security vulnerabilities while maintaining the educational value of the demo project.