From 98df0c9040b0c8e65c40e3bc2cee6ccfda646e13 Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Tue, 26 Sep 2023 12:24:59 -0700 Subject: [PATCH] chore(build): enable CodeQL (#1026) * Create codeql.yml * setup pnpm * sq.Eq{"ras.status": params.Filters.PushStatus} * enable extended and quality * fix: code scanning alert #58 #57 https://github.com/autobrr/autobrr/security/code-scanning/58 https://github.com/autobrr/autobrr/security/code-scanning/57 * fix: linting issues for code scanning 60, 59, 56 https://github.com/autobrr/autobrr/security/code-scanning/60 https://github.com/autobrr/autobrr/security/code-scanning/59 https://github.com/autobrr/autobrr/security/code-scanning/56 --------- Co-authored-by: Fabricio Silva --- .github/workflows/codeql.yml | 97 ++++++++++++++++++++++++ internal/database/release.go | 2 +- web/src/api/APIClient.ts | 4 +- web/src/hooks/hooks.ts | 2 +- web/src/screens/filters/_configParser.ts | 11 +-- 5 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..b276d71 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,97 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "develop", "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "develop" ] + schedule: + - cron: '20 13 * * 6' + +jobs: + analyze: + name: Analyze + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners + # Consider using larger runners for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go', 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Node + uses: actions/setup-node@v3 + with: + node-version: '18.17.0' + + - name: Set up corepack + run: corepack enable + + # It can not be done before enable corepack + - name: Set up cache + uses: actions/setup-node@v3 + with: + cache: pnpm + cache-dependency-path: web/pnpm-lock.yaml + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/internal/database/release.go b/internal/database/release.go index 9ef2df6..48a93ff 100644 --- a/internal/database/release.go +++ b/internal/database/release.go @@ -200,7 +200,7 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain if params.Filters.PushStatus != "" { subQueryBuilder = subQueryBuilder.InnerJoin("release_action_status ras ON r.id = ras.release_id").Where(sq.Eq{"ras.status": params.Filters.PushStatus}) - countQuery = countQuery.InnerJoin("release_action_status ras ON r.id = ras.release_id").Where("ras.status = '" + params.Filters.PushStatus + `'`) + countQuery = countQuery.InnerJoin("release_action_status ras ON r.id = ras.release_id").Where(sq.Eq{"ras.status": params.Filters.PushStatus}) } subQuery, subArgs, err := subQueryBuilder.ToSql() diff --git a/web/src/api/APIClient.ts b/web/src/api/APIClient.ts index 9787774..f571b84 100644 --- a/web/src/api/APIClient.ts +++ b/web/src/api/APIClient.ts @@ -50,7 +50,7 @@ export async function HttpClient( for (const [key, value] of Object.entries(config.queryString)) { const serializedKey = encodeRFC3986URIComponent(key); - if (typeof(value) === undefined) { + if (typeof(value) === "undefined") { // Skip case when the value is undefined. // The solution in this case is to use the request body instead with JSON continue; @@ -59,7 +59,7 @@ export async function HttpClient( // e.g. ?a=1&a=2&a=3 value.forEach((child) => { // Skip undefined member values - const v = typeof(child) !== undefined ? String(child) : ""; + const v = typeof(child) !== "undefined" ? String(child) : ""; if (v.length) { params.push(`${serializedKey}=${encodeRFC3986URIComponent(v)}`); } diff --git a/web/src/hooks/hooks.ts b/web/src/hooks/hooks.ts index 3082c43..b0f0784 100644 --- a/web/src/hooks/hooks.ts +++ b/web/src/hooks/hooks.ts @@ -12,7 +12,7 @@ export function useToggle(initialValue = false): [boolean, () => void] { return [value, toggle]; } -const isBrowser = typeof window !== "undefined"; +const isBrowser = typeof(window) !== "undefined"; const getInitialState = (query: string, defaultState?: boolean) => { // Prevent a React hydration mismatch when a default value is provided by not defaulting to window.matchMedia(query).matches. diff --git a/web/src/screens/filters/_configParser.ts b/web/src/screens/filters/_configParser.ts index e0954ac..235644a 100644 --- a/web/src/screens/filters/_configParser.ts +++ b/web/src/screens/filters/_configParser.ts @@ -9,7 +9,7 @@ type ValueObject = Record; class ParserFilter { public values: ValueObject = {}; public warnings: string[] = []; - + public name: string; constructor(name: string) { @@ -21,14 +21,14 @@ class ParserFilter { public OnParseLine(key: string, value: string) { if (key in CONST.FILTER_SUBSTITUTION_MAP) { - key = CONST.FILTER_SUBSTITUTION_MAP[key] + key = CONST.FILTER_SUBSTITUTION_MAP[key]; } switch (key) { case "log_score": // In this case we need to set 2 properties in autobrr instead of only 1 this.values["log"] = true; - + // log_score is an integer const delim = value.indexOf("-"); if (delim !== -1) { @@ -202,8 +202,9 @@ class ParserIrcChannel { } // erm.. todo? -const TRACKER = "tracker" as const; -const OPTIONS = "options" as const; +// const TRACKER = "tracker" as const; +// const OPTIONS = "options" as const; + // *cough* later dude, trust me *cough* const FILTER = "filter" as const; const SERVER = "server" as const;