codeql.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. name: "CodeQL"
  4. on:
  5. # run on every push to the feature-development branch
  6. # the main branch is covered by below cron plan
  7. push:
  8. branches:
  9. - dev/**
  10. # midnight UTC on the latest commit on the main branch
  11. schedule:
  12. - cron: "0 0 * * *"
  13. # allow to be triggered manually
  14. workflow_dispatch:
  15. jobs:
  16. analyze:
  17. # only run this job if the repository is not a fork
  18. # if want to run this job on a fork, please remove the if condition
  19. if: github.repository == 'bytecodealliance/wasm-micro-runtime'
  20. name: Analyze
  21. # Runner size impacts CodeQL analysis time. To learn more, please see:
  22. # - https://gh.io/recommended-hardware-resources-for-running-codeql
  23. # - https://gh.io/supported-runners-and-hardware-resources
  24. # - https://gh.io/using-larger-runners
  25. # Consider using larger runners for possible analysis time improvements.
  26. # But it is not free, so please be aware of the cost.
  27. runs-on: ubuntu-22.04
  28. timeout-minutes: 360
  29. strategy:
  30. fail-fast: false
  31. matrix:
  32. #TODO: add actions
  33. language: ["cpp"]
  34. permissions:
  35. contents: read
  36. actions: read
  37. security-events: write
  38. steps:
  39. - name: Checkout repository
  40. uses: actions/checkout@v6.0.1
  41. with:
  42. submodules: recursive
  43. # Initializes the CodeQL tools for scanning.
  44. - name: Initialize CodeQL
  45. uses: github/codeql-action/init@v4.31.9
  46. with:
  47. languages: ${{ matrix.language }}
  48. # 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
  49. # queries: security-extended,security-and-quality
  50. queries: security-and-quality
  51. config-file: ./.github/codeql/codeql_config.yml
  52. - run: |
  53. ./.github/scripts/codeql_buildscript.sh || exit 1
  54. - name: Perform CodeQL Analysis
  55. uses: github/codeql-action/analyze@v4.31.9
  56. with:
  57. category: "/language:${{matrix.language}}"
  58. upload: false
  59. id: step1
  60. # - cpp/alloca-in-loop is about touch_pages() which is intended to
  61. # - cpp/command-line-injection is about bh_system() which is used to
  62. # - cpp/path-injection is used in bh_read_file_to_buffer() to load a .wasm.
  63. # or operate a stack usage file which is not sensitive or generate a .aot
  64. # - cpp/suspicious-pointer-scaling
  65. # - wasm_runtime_invoke_native() used to trivial registers
  66. # - cpp/uncontrolled-process-operation is about dlopen() which is used by
  67. # native libraries registrations.
  68. # - cpp/world-writable-file-creation is about fopen() a temporary file
  69. # for perf-PID.map or .aot(wamrc). The permission isn't sensitive.
  70. # file.
  71. #
  72. # execute customized compiler
  73. - name: Filter out unwanted errors and warnings
  74. uses: advanced-security/filter-sarif@v1
  75. with:
  76. patterns: |
  77. ## Exclude files and directories
  78. -**/build/**
  79. -**/core/deps/**
  80. -**/cmake*/Modules/**
  81. -**/test*/**
  82. -**/wasm-app*/**
  83. ## Exclude rules 1. Related to formatting, style
  84. -**:cpp/commented-out-code
  85. -**:cpp/complex-condition
  86. -**:cpp/empty-if
  87. -**:cpp/fixme-comment
  88. -**:cpp/include-non-header
  89. -**:cpp/long-switch
  90. -**:cpp/poorly-documented-function
  91. -**:cpp/trivial-switch
  92. -**:cpp/unused-local-variable
  93. -**:cpp/unused-static-function
  94. -**:cpp/unused-static-variable
  95. -**:cpp/use-of-goto
  96. ## Exclude rules 2. Related to special usage of APIs
  97. -**:cpp/alloca-in-loop
  98. -**:cpp/command-line-injection
  99. -**:cpp/path-injection
  100. -core/iwasm/common/wasm_runtime_common.c:cpp/suspicious-pointer-scaling
  101. -**:cpp/uncontrolled-process-operation
  102. -**:cpp/world-writable-file-creation
  103. input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
  104. output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
  105. - name: Upload CodeQL results to code scanning
  106. uses: github/codeql-action/upload-sarif@v4.31.9
  107. with:
  108. sarif_file: ${{ steps.step1.outputs.sarif-output }}
  109. category: "/language:${{matrix.language}}"
  110. - name: Upload CodeQL results as an artifact
  111. uses: actions/upload-artifact@v6.0.0
  112. with:
  113. name: codeql-results
  114. path: ${{ steps.step1.outputs.sarif-output }}
  115. retention-days: 10
  116. - name: Fail if an error is found
  117. run: |
  118. ./.github/scripts/codeql_fail_on_error.py \
  119. ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
  120. env:
  121. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  122. GITHUB_REPOSITORY: ${{ github.repository }}