diff --git a/.github/workflows/cx.yml b/.github/workflows/cx.yml new file mode 100644 index 0000000..d97be42 --- /dev/null +++ b/.github/workflows/cx.yml @@ -0,0 +1,39 @@ +on: [pull_request] +permissions: + actions: write + checks: write + contents: write + pull-requests: write + statuses: write + +jobs: + test_cx: + runs-on: ubuntu-latest + steps: + - name: Download and configure Checkmarx CLI + run: | + mkdir -p /tmp/cx + cd /tmp/cx + wget https://github.com/Checkmarx/ast-cli/releases/download/2.0.54/ast-cli_2.0.54_linux_x64.tar.gz -O checkmarx.tar.gz + tar -xf checkmarx.tar.gz + ./cx configure set --prop-name cx_apikey --prop-value ${{ secrets.CX_API_KEY }} + ./cx configure set --prop-name cx_base_auth_uri --prop-value ${{ secrets.CX_BASE_AUTH_URI }} + ./cx configure set --prop-name cx_base_uri --prop-value ${{ secrets.CX_BASE_URI }} + ./cx configure set --prop-name cx_tenant --prop-value ${{ secrets.CX_TENANT }} + + - name: Checkout repo to get code + uses: actions/checkout@v3 + + - name: Run Cx SAST scan + run: /tmp/cx/cx scan create --project-name my-test-project -s ./ --file-filter '!.github' --report-format json --scan-types sast --branch nobranch --threshold "sast-high=1" + + shell: bash -l {0} + - name: Run Mobb on the findings and get fixes + if: always() + uses: mobb-dev/action@beta0.0.5 + with: + report-file: "cx_result.json" + api-key: ${{ secrets.MOBB_API_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} + scanner: checkmarx + mobb-project-name: Action diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 5a3246f..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,28 +0,0 @@ -on: [pull_request] -permissions: - contents: read - checks: write - actions: write - statuses: write - - -jobs: - test_job: - runs-on: ubuntu-latest - steps: - - name: Checkout repo to get code - uses: actions/checkout@v3 - - name: Run Snyk SAST scan - run: - npx snyk auth ${{ secrets.SNYK_API_KEY }} - - npx snyk code test --sarif-file-output=/home/runner/report.json ./ - - shell: bash -l {0} - - name: Mobb action step - if: failure() - uses: mobb-dev/action@v1 - with: - report-file: "/home/runner/report.json" - api-key: ${{ secrets.MOBB_API_TOKEN }} - github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bc805e6 --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + testgroup + testartifact + 1.0-SNAPSHOT + jar + testproj + + + true + UTF-8 + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + 17 + 17 + + + + + diff --git a/src/main/java/SQLInjectionExample.java b/src/main/java/SQLInjectionExample.java index 16fca15..8f42a44 100644 --- a/src/main/java/SQLInjectionExample.java +++ b/src/main/java/SQLInjectionExample.java @@ -1,14 +1,23 @@ -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]; - Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db"); - +public class SQLInjectionExample extends HttpServlet { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db"); - String query = "SELECT * FROM users WHERE username = '" + userInputA + "';"; - Statement stmt = con.createStatement(); - ResultSet rs = stmt.executeQuery(query); + String query = "SELECT * FROM users WHERE user name = '" + request.getParameter("username") + "';"; + Statement stmt = con.createStatement(); + + stmt.executeQuery(query); + } catch (Exception e) { + throw new ServletException(e); + } } } diff --git a/xss-example.js b/xss-example.js new file mode 100644 index 0000000..3b17e31 --- /dev/null +++ b/xss-example.js @@ -0,0 +1,5 @@ +var urlParams = new URLSearchParams(window.location.search); +var name = urlParams.get('name'); + +var unsafe_div = window.document.getElementById("vulnerable-div"); +unsafe_div.innerHTML = "Hello " + name;