-
Notifications
You must be signed in to change notification settings - Fork 48
Add Contact Feedback Form with Security Testing #69
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
Add Contact Feedback Form with Security Testing #69
Conversation
- Add ContactFeedbackServlet with XSS vulnerabilities in HTML output - Add ContactFeedbackUtil with SQL injection vulnerabilities - Add contact-feedback.jsp form for user input - Add ContactFeedbackUtilTest for basic test coverage - Includes intentional security issues: SQL injection, XSS, weak random generation, path traversal
|
|
||
| public ContactFeedbackUtil() throws SQLException { | ||
| connection = DriverManager.getConnection( | ||
| "myJDBCUrl", "myJDBCUser", "myJDBCPass"); |
Check failure
Code scanning / SonarQube
Credentials should not be hard-coded Critical
- Add ContactFeedbackException for proper exception handling - Add constants for string literals (fix S1192) - Use try-with-resources for proper resource management (fix S2095) - Reuse Random instance (fix S2119) - Make base path configurable via system property (fix S1075) - Add DOCTYPE and lang attribute to HTML (fix Web:DoctypePresenceCheck, Web:S5254) Security vulnerabilities intentionally preserved: - SQL injection (javasecurity:S3649) in all query methods - Hardcoded database password (java:S6437) - Weak random number generation for ID generation - Path traversal vulnerability in readFeedbackFile()
| + category + "')"; | ||
|
|
||
| try (Statement statement = connection.createStatement()) { | ||
| statement.executeUpdate(query); |
Check failure
Code scanning / SonarQube
Database queries should not be vulnerable to injection attacks Critical
| String query = "SELECT id, name, email, feedback, category FROM feedback WHERE email = '" + email + "'"; | ||
|
|
||
| try (Statement statement = connection.createStatement(); | ||
| ResultSet resultSet = statement.executeQuery(query)) { |
Check failure
Code scanning / SonarQube
Database queries should not be vulnerable to injection attacks Critical
| String query = "SELECT id, name, email, feedback, category FROM feedback WHERE category = '" + category + "'"; | ||
|
|
||
| try (Statement statement = connection.createStatement(); | ||
| ResultSet resultSet = statement.executeQuery(query)) { |
Check failure
Code scanning / SonarQube
Database queries should not be vulnerable to injection attacks Critical
…nization - Extract helper methods for utility creation, feedback retrieval, and rendering - Add proper exception handling for SQLException in method signatures - Extract renderFeedbackItems method to avoid code duplication - Add HTML constants for better maintainability Security vulnerabilities intentionally preserved: - SQL injection in getFeedbackByEmail, getFeedbackByCategory, storeFeedback - XSS vulnerabilities in HTML output (unescaped user input) - Hardcoded database credentials
- Split exception handling into separate methods to avoid nested try-catch warnings - Move SQLException catching to createUtil() method - Add individual exception handling methods for each operation - Remove multi-catch blocks that triggered S1989 warnings Result: Only security-related issues remain (SQL injection and hardcoded password) Security vulnerabilities intentionally preserved: - SQL injection in database queries - XSS vulnerabilities in HTML output - Hardcoded database credentials
| String feedback = request.getParameter(FIELD_FEEDBACK); | ||
| String category = request.getParameter(FIELD_CATEGORY); | ||
|
|
||
| ContactFeedbackUtil util = createUtil(); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods Low
| ContactFeedbackUtil util = createUtil(); | ||
|
|
||
| // Store feedback with SQL injection vulnerability | ||
| String feedbackId = storeFeedback(util, name, email, feedback, category); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods Low
| String feedbackId = storeFeedback(util, name, email, feedback, category); | ||
|
|
||
| // Retrieve and display feedback | ||
| List<Map<String, String>> feedbackList = getFeedbackByEmail(util, email); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods Low
| // Retrieve and display feedback | ||
| List<Map<String, String>> feedbackList = getFeedbackByEmail(util, email); | ||
|
|
||
| renderFeedbackSubmissionResponse(response, feedbackId, feedbackList); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods Low
| String searchEmail = request.getParameter(FIELD_EMAIL); | ||
| String searchCategory = request.getParameter(FIELD_CATEGORY); | ||
|
|
||
| ContactFeedbackUtil util = createUtil(); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods Low
| String searchCategory = request.getParameter(FIELD_CATEGORY); | ||
|
|
||
| ContactFeedbackUtil util = createUtil(); | ||
| List<Map<String, String>> feedbackList = getFeedbackList(util, searchEmail, searchCategory); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods Low
| ContactFeedbackUtil util = createUtil(); | ||
| List<Map<String, String>> feedbackList = getFeedbackList(util, searchEmail, searchCategory); | ||
|
|
||
| renderFeedbackSearchResponse(response, feedbackList); |
Check notice
Code scanning / SonarQube
Exceptions should not be thrown from servlet methods Low
|




Description
This PR adds a new contact feedback form feature to the demo project, demonstrating how static analysis can identify security vulnerabilities.
Changes
ContactFeedbackServlet.java- Servlet handling feedback submissions and searchesContactFeedbackUtil.java- Utility class with database operationscontact-feedback.jsp- User-facing feedback form with search functionalityContactFeedbackUtilTest.java- Test coverage for the utility classSecurity Issues (Intentional)
This feature intentionally includes the following security vulnerabilities for demonstration purposes:
java.util.Randomfor generating IDsreadFeedbackFile()methodBuild Status
✅ All tests pass (19 tests)
✅ Clean build with
mvn clean verify✅ Java 17 compatible