Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id "org.sonarqube" version "3.4.0.2513"
}

group 'org.example'
Expand All @@ -16,4 +17,4 @@ dependencies {

test {
useJUnitPlatform()
}
}
18 changes: 15 additions & 3 deletions src/main/java/example/Start.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Start {
Expand All @@ -15,7 +13,21 @@ public static void main(String[] args) {
}

private static void doVulnerableCode() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:derby:memory:myDB;create=true", "login", "");
new Vulnerable().vulnerable();
}

private static void anotherVulnerableCode() {
var regex = "/^([a-zA-Z0-9])(([\\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$/";
if (!"some phrase".matches(regex)){
throw new Error("Invalid mail format");
}
}

private static void moreVulnerableCode() {
var regex = "/^([a-zA-Z0-9])(([\\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$/";
if (!"some phrase test".matches(regex)){
throw new Error("Invalid e-mail format");
}
}

}
15 changes: 15 additions & 0 deletions src/main/java/example/Vulnerable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Vulnerable {
public Connection vulnerable() {
try {
return DriverManager.getConnection("jdbc:derby:memory:myDB;create=true", "login", "");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}