diff --git a/build.gradle b/build.gradle index 3cae2d7..1cc8ad8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id "org.sonarqube" version "3.4.0.2513" } group 'org.example' @@ -16,4 +17,4 @@ dependencies { test { useJUnitPlatform() -} \ No newline at end of file +} diff --git a/src/main/java/example/Start.java b/src/main/java/example/Start.java index ca08ee5..63df820 100644 --- a/src/main/java/example/Start.java +++ b/src/main/java/example/Start.java @@ -1,6 +1,5 @@ package example; -import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -15,7 +14,29 @@ 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 doVulnerableCode(String output) { + try { + DriverManager.getConnection("jdbc:derby:memory:myDB;create=true", "login", ""); + } catch (SQLException e) { + throw new RuntimeException(output + " " + e); + } + } + + 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"); + } } } diff --git a/src/main/java/example/Vulnerable.java b/src/main/java/example/Vulnerable.java new file mode 100644 index 0000000..5aad3d1 --- /dev/null +++ b/src/main/java/example/Vulnerable.java @@ -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); + } + } +}