Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions vulnerable-example.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>User Search - Vulnerable Example</title>
</head>
<body>
<h1>User Search Portal</h1>

<%
// Hardcoded credentials - Security violation
String dbPassword = "MySecretP@ssw0rd123!";

Check failure on line 13 in vulnerable-example.jsp

View check run for this annotation

Cycode Security / Cycode: Secrets

vulnerable-example.jsp#L13

Generic Password found

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cycode: Secret of type: 'Generic Password' was found.
Severity: Medium
Confidence Score: 94%
SHA: 2c3544790f

Description

A generic secret or password is an authentication token used to access a computer or application and is assigned to a password variable.

Cycode Remediation Guideline

❗ How to revoke


  • Change the password or secret in the system or application where it is used.
  • Update any services, applications, or scripts that use the old password or secret with the new one.
  • Invalidate any sessions or tokens that were authenticated using the old password or secret.

Tell us how you wish to proceed using one of the following commands:

Tag Short Description
#cycode_secret_revoked Applies to this secret value for all repos in your organization
#cycode_secret_false_positive <reason> Applies to this secret value for all repos in your organization

⚠️ When commenting on Github, you may need to refresh the page to see the latest updates.

String apiKey = "sk-1234567890abcdefghijklmnop";

Check failure on line 14 in vulnerable-example.jsp

View check run for this annotation

Cycode Security / Cycode: Secrets

vulnerable-example.jsp#L14

Generic Password found

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cycode: Secret of type: 'Generic Password' was found.
Severity: Medium
Confidence Score: 97%
SHA: b4108cde21

Description

A generic secret or password is an authentication token used to access a computer or application and is assigned to a password variable.

Cycode Remediation Guideline

❗ How to revoke


  • Change the password or secret in the system or application where it is used.
  • Update any services, applications, or scripts that use the old password or secret with the new one.
  • Invalidate any sessions or tokens that were authenticated using the old password or secret.

Tell us how you wish to proceed using one of the following commands:

Tag Short Description
#cycode_secret_revoked Applies to this secret value for all repos in your organization
#cycode_secret_false_positive <reason> Applies to this secret value for all repos in your organization

⚠️ When commenting on Github, you may need to refresh the page to see the latest updates.


// SQL Injection vulnerability - User input directly concatenated into SQL query
String userInput = request.getParameter("username");
String searchQuery = request.getParameter("search");

if (userInput != null && !userInput.isEmpty()) {
try {
// Insecure database connection with hardcoded credentials
String dbUrl = "jdbc:mysql://localhost:3306/userdb";
String dbUser = "admin";
Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);

// SQL Injection vulnerability - no prepared statement
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM users WHERE username = '" + userInput + "' OR email = '" + userInput + "'";
ResultSet rs = stmt.executeQuery(sql);

out.println("<h2>Search Results:</h2>");
out.println("<table border='1'>");

while (rs.next()) {
// XSS vulnerability - unescaped output
out.println("<tr>");
out.println("<td>" + rs.getString("username") + "</td>");
out.println("<td>" + rs.getString("email") + "</td>");
out.println("<td>" + rs.getString("role") + "</td>");
out.println("</tr>");
}

out.println("</table>");

rs.close();
stmt.close();
conn.close();

} catch (Exception e) {
// Information disclosure - exposing stack trace
out.println("<pre>");
e.printStackTrace(new java.io.PrintWriter(out));
out.println("</pre>");
}
}

// XSS vulnerability - reflecting user input without sanitization
if (searchQuery != null) {
out.println("<p>You searched for: " + searchQuery + "</p>");
}
%>

<form method="GET" action="">
<label>Username:</label>
<input type="text" name="username" />
<br/><br/>
<label>Search:</label>
<input type="text" name="search" />
<br/><br/>
<input type="submit" value="Search" />
</form>

<!-- Debug information exposure -->
<div style="display:none;">
<!-- API Key: <%= apiKey %> -->
<!-- DB Password: <%= dbPassword %> -->
</div>

<%
// Command injection vulnerability
String command = request.getParameter("cmd");
if (command != null) {
Runtime.getRuntime().exec(command);
}

// Path traversal vulnerability
String filename = request.getParameter("file");
if (filename != null) {
java.io.FileInputStream fis = new java.io.FileInputStream("/var/www/files/" + filename);
}
%>

</body>
</html>
Loading