Skip to content

Add Contact Feedback Form with Security Flows and CAPTCHA Validation#74

Open
sylvain-combe-sonarsource wants to merge 1 commit intomainfrom
feature/contact-feedback-form
Open

Add Contact Feedback Form with Security Flows and CAPTCHA Validation#74
sylvain-combe-sonarsource wants to merge 1 commit intomainfrom
feature/contact-feedback-form

Conversation

@sylvain-combe-sonarsource
Copy link
Contributor

Summary

This PR implements a new contact feedback form feature that demonstrates various security vulnerabilities for educational purposes in this Java security demo project.

Features Added

1. Contact Feedback Form (contact-feedback.jsp)

  • Modern, responsive web form for collecting user feedback
  • Fields: Name, Email, Subject, Message, Priority
  • Optional CAPTCHA validation with toggle functionality
  • Client-side validation
  • Success message display with submission token

2. ContactFeedbackServlet

Demonstrates multiple security vulnerabilities:

  • SQL Injection: Unparameterized queries in both GET and POST methods
  • XSS (Cross-Site Scripting): No output escaping in feedback display
  • Path Traversal: Direct file access without sanitization
  • Weak Cryptography: MD5 hashing for email
  • Weak Random Generation: Predictable token generation using Random
  • Information Disclosure: Logging sensitive data, tokens in URLs
  • Insecure File Storage: Writing sensitive data to files with predictable names

3. CaptchaServlet

  • Generates CAPTCHA images using the kaptcha library
  • Stores CAPTCHA text in session for validation
  • Configurable image dimensions and text properties

4. Dependencies

  • Added kaptcha 2.3.2 - an obsolete CAPTCHA library with known CVEs
  • This is intentional for demonstrating dependency vulnerabilities

5. GitHub Actions CI Workflow

  • Created .github/workflows/ci.yml for continuous integration
  • Runs on main branch and all feature branches (feature/**)
  • Also triggers on pull requests
  • Uses Java 17 with Temurin distribution
  • Runs mvn clean verify
  • Uploads test results and coverage reports as artifacts

Security Vulnerabilities (Intentional)

This feature demonstrates the following security issues that static analysis tools should detect:

  • SQL Injection vulnerabilities
  • Cross-Site Scripting (XSS)
  • Path Traversal
  • Use of weak cryptographic algorithms (MD5)
  • Predictable random number generation
  • Information disclosure through logging
  • Sensitive data in URL parameters
  • Use of vulnerable dependencies (kaptcha with CVEs)

Build Status

✅ All tests pass
✅ Maven clean verify succeeds

Testing

The feature has been built and verified locally with mvn clean verify.

- Implemented ContactFeedbackServlet with multiple security vulnerabilities:
  * SQL injection in feedback retrieval and storage
  * XSS vulnerability in feedback display
  * Path traversal in file viewing
  * Weak random token generation
  * Weak MD5 hashing for email
  * Logging of sensitive information
  * Sensitive data in URL parameters

- Added CaptchaServlet using obsolete kaptcha library (2.3.2) with known CVEs
- Created contact-feedback.jsp form with optional CAPTCHA validation
- Added kaptcha dependency to pom.xml
- Created GitHub Actions CI workflow for feature branches and main
- Workflow runs on Java 17 and includes test and coverage artifacts
@sonar-nautilus
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
29 New issues
5 Security Hotspots
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE SonarQube for IDE

if ("true".equals(success)) {
%>
<div class="success-message">
Thank you for your feedback! Your submission token is: <%= token %>

Check failure

Code scanning / SonarQube

Endpoints should not be vulnerable to reflected cross-site scripting (XSS) attacks Critical

Change this code to not reflect unsanitized user-controlled data. See more on SonarQube
message + "', '" + priority + "', '" + token + "', '" + emailHash + "')";

Statement statement = connection.createStatement();
statement.executeUpdate(query);

Check failure

Code scanning / SonarQube

Database queries should not be vulnerable to injection attacks Critical

Change this code to not construct SQL queries directly from user-controlled data. See more on SonarQube
String message, String priority, String token, String emailHash) throws Exception {
// SQL Injection vulnerability
Connection connection = DriverManager.getConnection(
"myJDBCUrl", "myJDBCUser", "myJDBCPass");

Check failure

Code scanning / SonarQube

Credentials should not be hard-coded Critical

Revoke and change this password, as it is compromised. See more on SonarQube

String query = "SELECT * FROM feedback WHERE id = " + feedbackId;
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);

Check failure

Code scanning / SonarQube

Database queries should not be vulnerable to injection attacks Critical

Change this code to not construct SQL queries directly from user-controlled data. See more on SonarQube
private List<String> getFeedbackById(String feedbackId) throws Exception {
// SQL Injection vulnerability
Connection connection = DriverManager.getConnection(
"myJDBCUrl", "myJDBCUser", "myJDBCPass");

Check failure

Code scanning / SonarQube

Credentials should not be hard-coded Critical

Revoke and change this password, as it is compromised. See more on SonarQube
out.println("</body></html>");
out.close();
} catch (Exception e) {
throw new ServletException(e);

Check notice

Code scanning / SonarQube

Exceptions should not be thrown from servlet methods Low

Handle the "ServletException" thrown here in a "try/catch" block. See more on SonarQube
ServletOutputStream out = response.getOutputStream();
ImageIO.write(captchaImage, "jpg", out);
out.flush();
out.close();

Check notice

Code scanning / SonarQube

Exceptions should not be thrown from servlet methods Low

Handle the following exception that could be thrown by "close": IOException. See more on SonarQube
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
ImageIO.write(captchaImage, "jpg", out);
out.flush();

Check notice

Code scanning / SonarQube

Exceptions should not be thrown from servlet methods Low

Handle the following exception that could be thrown by "flush": IOException. See more on SonarQube
// Send image response
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
ImageIO.write(captchaImage, "jpg", out);

Check notice

Code scanning / SonarQube

Exceptions should not be thrown from servlet methods Low

Handle the following exception that could be thrown by "write": IOException. See more on SonarQube

// Send image response
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();

Check notice

Code scanning / SonarQube

Exceptions should not be thrown from servlet methods Low

Handle the following exception that could be thrown by "getOutputStream": IOException. See more on SonarQube
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant