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
47 changes: 47 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on: [pull_request]
permissions:
actions: write
checks: write
contents: write
pull-requests: write
statuses: write

jobs:
test_codeql:
runs-on: ubuntu-latest
steps:
- name: Setup Java on this machine
uses: actions/setup-java@v3
with:
distribution: "oracle"
java-version: "19"
- name: Setup Maven on this machine
uses: stCarolas/setup-maven@v4.5
with:
maven-version: 3.8.6

- name: Checkout repo to get code
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: java

- name: Run CodeQL autobuild
uses: github/codeql-action/autobuild@v2

- name: Run CodeQL SAST scan
uses: github/codeql-action/analyze@v2
with:
output: ../results

- name: Run Mobb on the findings and get fixes
if: always()
uses: mobb-dev/action@beta0.0.4
with:
report-file: ../results/java.sarif
api-key: ${{ secrets.MOBB_API_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
scanner: codeql
mobb-project-name: Action
28 changes: 0 additions & 28 deletions .github/workflows/main.yml

This file was deleted.

38 changes: 38 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testgroup</groupId>
<artifactId>testartifact</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testproj</name>

<properties>
<maven.test.skip>true</maven.test.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
26 changes: 17 additions & 9 deletions src/main/java/SQLInjectionExample.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class SQLInjectionExample {
public static void main(String[] args) throws SQLException {
String userInputA = args[1];
public class SQLInjectionExample extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db");

String query = "SELECT * FROM users WHERE username = '" + request.getParameter("username") + "';";
Statement stmt = con.createStatement();

String query = "SELECT * FROM users WHERE username = '" + userInputA + "';";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
stmt.executeQuery(query);

Check failure

Code scanning / CodeQL

Query built from user-controlled sources

This query depends on a [user-provided value](1).
} catch (Exception e) {
throw new ServletException(e);
}
}
}