Skip to content

Commit 372f123

Browse files
Copilotcommjoen
andcommitted
Fix formatting issues in Challenge 57 files
Co-authored-by: commjoen <[email protected]>
1 parent 7a4d274 commit 372f123

File tree

7 files changed

+25
-21
lines changed

7 files changed

+25
-21
lines changed

src/main/java/org/owasp/wrongsecrets/challenges/docker/Challenge57.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
public class Challenge57 implements Challenge {
1616

1717
// Simulated database connection string with embedded credentials
18-
private static final String DB_CONNECTION_STRING =
18+
private static final String DB_CONNECTION_STRING =
1919
"jdbc:postgresql://db.example.com:5432/userdb?user=dbadmin&password=SuperSecretDB2024!&ssl=true";
20-
20+
2121
private static final String EXPECTED_SECRET = "SuperSecretDB2024!";
2222

2323
@Override
@@ -31,27 +31,30 @@ public boolean answerCorrect(String answer) {
3131
}
3232

3333
/**
34-
* This method simulates what happens when an application tries to connect to a database
35-
* but fails, exposing the full connection string (including credentials) in error messages.
36-
* This is a common real-world mistake where developers include sensitive information
37-
* in connection strings and don't properly handle/sanitize database connection errors.
34+
* This method simulates what happens when an application tries to connect to a database but
35+
* fails, exposing the full connection string (including credentials) in error messages. This is a
36+
* common real-world mistake where developers include sensitive information in connection strings
37+
* and don't properly handle/sanitize database connection errors.
3838
*/
3939
public String simulateDatabaseConnectionError() {
4040
try {
41-
// This will fail since we don't have a real database, but it demonstrates
41+
// This will fail since we don't have a real database, but it demonstrates
4242
// how connection errors can expose credentials
4343
Connection conn = DriverManager.getConnection(DB_CONNECTION_STRING);
4444
conn.close();
4545
return "Connection successful";
4646
} catch (SQLException e) {
4747
// Poor error handling - exposing the full connection string in the error message
48-
String errorMessage = "Database connection failed with connection string: " + DB_CONNECTION_STRING
49-
+ "\nError: " + e.getMessage();
50-
48+
String errorMessage =
49+
"Database connection failed with connection string: "
50+
+ DB_CONNECTION_STRING
51+
+ "\nError: "
52+
+ e.getMessage();
53+
5154
// Log the error (another way credentials get exposed)
5255
log.error("Failed to connect to database: {}", errorMessage);
53-
56+
5457
return errorMessage;
5558
}
5659
}
57-
}
60+
}

src/main/java/org/owasp/wrongsecrets/challenges/docker/Challenge57Controller.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public class Challenge57Controller {
1414
private final Challenge57 challenge;
1515

1616
/**
17-
* Endpoint to trigger a database connection error that exposes connection string with credentials.
18-
* This simulates what happens when applications try to connect to unavailable databases.
17+
* Endpoint to trigger a database connection error that exposes connection string with
18+
* credentials. This simulates what happens when applications try to connect to unavailable
19+
* databases.
1920
*/
2021
@GetMapping("/error-demo/database-connection")
2122
public String triggerDatabaseError() {
2223
log.info("Attempting database connection for Challenge 57...");
2324
return challenge.simulateDatabaseConnectionError();
2425
}
25-
}
26+
}

src/main/resources/explanations/challenge57.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ Visit the `/error-demo/database-connection` endpoint to simulate a database conn
3030

3131
Can you find the database password that gets exposed when the application tries to connect to the database?
3232

33-
**Hint:** Look for database connection error messages that reveal more than they should.
33+
**Hint:** Look for database connection error messages that reveal more than they should.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Try visiting the `/error-demo/database-connection` endpoint to trigger a database connection error. Look at both the HTTP response and the application logs - database connection failures often expose connection strings with embedded credentials in error messages.
1+
Try visiting the `/error-demo/database-connection` endpoint to trigger a database connection error. Look at both the HTTP response and the application logs - database connection failures often expose connection strings with embedded credentials in error messages.

src/main/resources/explanations/challenge57_reason.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ The application doesn't sanitize sensitive information before logging or display
4040
4141
5. **Monitor and audit:** Regularly review logs and error messages to ensure sensitive information isn't being inadvertently exposed.
4242
43-
This type of credential exposure is extremely common in production applications and represents one of the most frequent ways database credentials are accidentally leaked.
43+
This type of credential exposure is extremely common in production applications and represents one of the most frequent ways database credentials are accidentally leaked.

src/test/java/org/owasp/wrongsecrets/challenges/docker/Challenge57ControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ void triggerDatabaseErrorShouldReturnErrorMessage() {
2828
assertThat(result).isEqualTo(expectedError);
2929
org.mockito.Mockito.verify(challenge).simulateDatabaseConnectionError();
3030
}
31-
}
31+
}

src/test/java/org/owasp/wrongsecrets/challenges/docker/Challenge57Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ void answerCorrectShouldTrimWhitespace() {
3737
void simulateDatabaseConnectionErrorShouldExposeConnectionString() {
3838
var challenge = new Challenge57();
3939
String errorMessage = challenge.simulateDatabaseConnectionError();
40-
40+
4141
// Verify that the error message contains the exposed connection string
4242
assertThat(errorMessage).contains("jdbc:postgresql://db.example.com:5432/userdb");
4343
assertThat(errorMessage).contains("user=dbadmin");
4444
assertThat(errorMessage).contains("password=SuperSecretDB2024!");
4545
assertThat(errorMessage).contains("Database connection failed");
4646
}
47-
}
47+
}

0 commit comments

Comments
 (0)