From 726d49e73736b2e385d4704f4ab0f25a311c8513 Mon Sep 17 00:00:00 2001 From: StepSecurity Bot Date: Sat, 30 Sep 2023 13:12:50 -0700 Subject: [PATCH] [StepSecurity] Apply security best practices (#139) * [StepSecurity] Apply security best practices Signed-off-by: StepSecurity Bot * Update test.yml Update Node versions, modify permissions for basic tests --------- Signed-off-by: StepSecurity Bot Co-authored-by: James Cullum (Pseudonym) --- .github/workflows/codeql-analysis.yml | 20 +++++++++--- .github/workflows/dependency-review.yml | 27 ++++++++++++++++ .github/workflows/scorecard.yml | 5 +++ .github/workflows/test.yml | 43 +++++++++++++++++-------- .pre-commit-config.yaml | 10 ++++++ 5 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/dependency-review.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ffe81be6..9524bd46 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -20,8 +20,15 @@ on: schedule: - cron: '40 12 * * 1' +permissions: + contents: read + jobs: analyze: + permissions: + actions: read # for github/codeql-action/init to get workflow details + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/autobuild to send a status report name: Analyze runs-on: ubuntu-latest @@ -34,12 +41,17 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed steps: + - name: Harden Runner + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 + with: + egress-policy: audit + - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@231aa2c8a89117b126725a0e11897209b7118144 # v1.1.39 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -50,7 +62,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@231aa2c8a89117b126725a0e11897209b7118144 # v1.1.39 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -64,4 +76,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@231aa2c8a89117b126725a0e11897209b7118144 # v1.1.39 diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 00000000..9bfe6712 --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,27 @@ +# Dependency Review Action +# +# This Action will scan dependency manifest files that change as part of a Pull Request, +# surfacing known-vulnerable versions of the packages declared or updated in the PR. +# Once installed, if the workflow run is marked as required, +# PRs introducing known-vulnerable packages will be blocked from merging. +# +# Source repository: https://github.com/actions/dependency-review-action +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: Harden Runner + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 + with: + egress-policy: audit + + - name: 'Checkout Repository' + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - name: 'Dependency Review' + uses: actions/dependency-review-action@0efb1d1d84fc9633afcdaad14c485cbbc90ef46c # v2.5.1 diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 6c5a14f8..5e0d5d82 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -31,6 +31,11 @@ jobs: # actions: read steps: + - name: Harden Runner + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 + with: + egress-policy: audit + - name: "Checkout code" uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0c0013f2..26f3d162 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,16 +8,20 @@ on: jobs: test_deno: runs-on: ubuntu-latest - + permissions: read-all strategy: matrix: deno-version: ["v1.x"] - steps: + - name: Harden Runner + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 + with: + egress-policy: audit + - name: Git Checkout Deno Module - uses: actions/checkout@v2 + uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0 - name: Use Deno Version ${{ matrix.deno-version }} - uses: denolib/setup-deno@v2 + uses: denolib/setup-deno@4df079f84f6c4ef488b04806df9af59e51d09bfb # v2.3.0 with: deno-version: ${{ matrix.deno-version }} - name: Test Module @@ -25,14 +29,20 @@ jobs: test_node: runs-on: ${{ matrix.os }} + permissions: read-all strategy: matrix: os: [windows-latest, ubuntu-latest, macos-latest] - node-version: [16.x, 18.x] + node-version: [18.x, 20.x] steps: - - uses: actions/checkout@v2 + - name: Harden Runner + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 + with: + egress-policy: audit + + - uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e # v1.4.6 with: node-version: ${{ matrix.node-version }} - run: npm ci @@ -46,18 +56,23 @@ jobs: needs: [test_node,test_deno] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Harden Runner + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 + with: + egress-policy: audit + + - uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0 with: fetch-depth: 0 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e # v1.4.6 with: node-version: '18.x' - - uses: denolib/setup-deno@v2 + - uses: denolib/setup-deno@4df079f84f6c4ef488b04806df9af59e51d09bfb # v2.3.0 with: deno-version: '1.x' - name: Get current package version id: package_version - uses: martinbeentjes/npm-get-version-action@v1.2.3 + uses: martinbeentjes/npm-get-version-action@7aa1d82604bb2dbe377a64ca35e692e6fe333c9c # v1.2.3 - run: deno task build - run: npm ci - run: npm run build @@ -65,14 +80,14 @@ jobs: - run: git config --global user.email "https://mailhide.io/e/Wno7k" - name: Check if tag already exists id: tag_exists - uses: mukunku/tag-exists-action@v1.0.0 + uses: mukunku/tag-exists-action@f8003af57c02ede2638326be67523df10cf6b10a # v1.0.0 with: tag: "${{ steps.package_version.outputs.current-version}}" env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} - name: Git Auto Commit Deno Artifacts if: steps.tag_exists.outputs.exists == 'false' - uses: stefanzweifel/git-auto-commit-action@v4.14.1 + uses: stefanzweifel/git-auto-commit-action@49620cd3ed21ee620a48530e81dba0d139c9cb80 # v4.14.1 with: commit_message: "[skip_ci] v${{ steps.package_version.outputs.current-version}}: Build artifacts for Deno" tagging_message: "${{ steps.package_version.outputs.current-version}}" @@ -81,6 +96,6 @@ jobs: - run: npm run publish-docs env: GH_TOKEN: ${{ secrets.GH_TOKEN }} - - uses: JS-DevTools/npm-publish@v1 + - uses: JS-DevTools/npm-publish@0f451a94170d1699fd50710966d48fb26194d939 # v1.4.3 with: token: ${{ secrets.NPM_AUTH_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..cba08601 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: +- repo: https://github.com/gitleaks/gitleaks + rev: v8.16.3 + hooks: + - id: gitleaks +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace