From 321629775eceaf149774d08871a4a7c7e210e98d Mon Sep 17 00:00:00 2001 From: Jaroslaw Zolnowski Date: 2023εΉ΄7月26ζ—₯ 12:39:58 +0200 Subject: [PATCH 1/2] build(codeql): enabling code scanning We can use CodeQL to identify vulnerabilities and errors in our JavaScript code and display the results as code scanning alerts on GitHub --- .github/workflows/codeql-analysis.yml | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..ca19053 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,85 @@ +# 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: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + paths-ignore: + - '**/*.md' + - '**/*.txt' + schedule: + - cron: '32 11 * * 3' + +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: ubuntu-latest + timeout-minutes: 360 + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ '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 + + # 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 + + # i️ 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}}" From 732d4f6e8099f50e7449ffb936c516dd15992a07 Mon Sep 17 00:00:00 2001 From: Jaroslaw Zolnowski Date: Wed, 2 Aug 2023 16:51:34 +0200 Subject: [PATCH 2/2] refactor(hooks): suppress the codeql warning regarding replacing only the first occurrence of '>' --- hooks/after_prepare/010_add_platform_class.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hooks/after_prepare/010_add_platform_class.js b/hooks/after_prepare/010_add_platform_class.js index bda3e41..21f8a8d 100755 --- a/hooks/after_prepare/010_add_platform_class.js +++ b/hooks/after_prepare/010_add_platform_class.js @@ -37,8 +37,13 @@ function addPlatformBodyTag(indexPath, platform) { newBodyTag = bodyTag.replace(classAttr, newClassAttr); } else { + // The bodyTag contains only the first found of `>`, due to the return of the first element of the array from method + // (findBodyTag)[https://github.com/xlts-dev/angularjs-ionic-v1/blob/c553c973d85142e66f119aed2fe3db83775f5f2b/hooks + // /after_prepare/010_add_platform_class.js#L57]. Therefore, we should replace only one tag. + // Fix https://github.com/xlts-dev/angularjs-ionic-v1/security/code-scanning/1 CodeQL warning + var closingBracketIdx = bodyTag.indexOf('>'); // add class attribute to the body tag - newBodyTag = bodyTag.replace('>', ' class="' + platformClass + ' ' + cordovaClass + '">'); + newBodyTag = bodyTag.slice(0, closingBracketIdx) + ' class="' + platformClass + ' ' + cordovaClass + '"' + bodyTag.slice(closingBracketIdx); } html = html.replace(bodyTag, newBodyTag);

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /