Act on CodeQL's suggestions for tightening security / improving performance (#338)

* Act on CodeQL's actions/missing-workflow-permissions

https://codeql.github.com/codeql-query-help/actions/actions-missing-workflow-permissions/

* Be more specific in the matched regex

And don't match a group if we don't need to match one

* Make it slightly faster since we know what after -otp-

I create a const because both expressions are looking for
the same thing
This commit is contained in:
Paulo F. Oliveira
2025-05-30 01:57:00 +01:00
committed by GitHub
parent 889e64e95a
commit 65066e38a0
8 changed files with 24 additions and 12 deletions
+3 -6
View File
@@ -1,6 +1,9 @@
--- ---
name: action name: action
permissions:
contents: read
on: on:
push: push:
branches: branches:
@@ -41,8 +44,6 @@ jobs:
name: Expected local npm actions name: Expected local npm actions
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main' if: github.ref != 'refs/heads/main'
permissions:
contents: read
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4 - uses: actions/setup-node@v4
@@ -56,8 +57,6 @@ jobs:
name: Action name: Action
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main' if: github.ref != 'refs/heads/main'
permissions:
contents: read
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: raven-actions/actionlint@v2 - uses: raven-actions/actionlint@v2
@@ -94,8 +93,6 @@ jobs:
unit_tests_macos: unit_tests_macos:
name: Unit tests (macOS) name: Unit tests (macOS)
runs-on: macos-latest runs-on: macos-latest
permissions:
contents: read
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v4 - uses: actions/setup-node@v4
+3
View File
@@ -1,6 +1,9 @@
--- ---
name: hexpm-mirrors name: hexpm-mirrors
permissions:
contents: read
on: on:
push: push:
branches: branches:
+1
View File
@@ -1,5 +1,6 @@
--- ---
name: macos name: macos
permissions: permissions:
contents: read contents: read
+3
View File
@@ -1,6 +1,9 @@
--- ---
name: ubuntu name: ubuntu
permissions:
contents: read
on: on:
push: push:
branches: branches:
@@ -1,6 +1,9 @@
--- ---
name: Update 3rd party licenses (automation) name: Update 3rd party licenses (automation)
permissions:
contents: write
on: on:
schedule: schedule:
- cron: '0 12 * * *' - cron: '0 12 * * *'
+3
View File
@@ -1,6 +1,9 @@
--- ---
name: windows name: windows
permissions:
contents: read
on: on:
push: push:
branches: branches:
+4 -3
View File
@@ -26068,10 +26068,11 @@ function requestedVersionFor(tool, version, originListing, mirrors) {
} }
async function getElixirVersion(exSpec0, otpVersion0) { async function getElixirVersion(exSpec0, otpVersion0) {
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2] const otpVersion = otpVersion0.match(/^(?:OTP-)?(.+)$/)[1]
let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1] let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1]
const userSuppliedOtp = exSpec0.match(/-otp-(\d+)/)?.[1] ?? null const otpSuffix = /-otp-(\d+)/
const userSuppliedOtp = exSpec0.match(otpSuffix)?.[1] ?? null
if (userSuppliedOtp && isVersion(userSuppliedOtp)) { if (userSuppliedOtp && isVersion(userSuppliedOtp)) {
otpVersionMajor = userSuppliedOtp otpVersionMajor = userSuppliedOtp
@@ -26079,7 +26080,7 @@ async function getElixirVersion(exSpec0, otpVersion0) {
const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] = const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
await getElixirVersions() await getElixirVersions()
const spec = exSpec0.replace(/-otp-.*$/, '') const spec = exSpec0.replace(otpSuffix, '')
const versions = elixirVersions const versions = elixirVersions
const elixirVersionFromSpec = getVersionFromSpec(spec, versions) const elixirVersionFromSpec = getVersionFromSpec(spec, versions)
+4 -3
View File
@@ -193,10 +193,11 @@ function requestedVersionFor(tool, version, originListing, mirrors) {
} }
async function getElixirVersion(exSpec0, otpVersion0) { async function getElixirVersion(exSpec0, otpVersion0) {
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2] const otpVersion = otpVersion0.match(/^(?:OTP-)?(.+)$/)[1]
let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1] let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1]
const userSuppliedOtp = exSpec0.match(/-otp-(\d+)/)?.[1] ?? null const otpSuffix = /-otp-(\d+)/
const userSuppliedOtp = exSpec0.match(otpSuffix)?.[1] ?? null
if (userSuppliedOtp && isVersion(userSuppliedOtp)) { if (userSuppliedOtp && isVersion(userSuppliedOtp)) {
otpVersionMajor = userSuppliedOtp otpVersionMajor = userSuppliedOtp
@@ -204,7 +205,7 @@ async function getElixirVersion(exSpec0, otpVersion0) {
const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] = const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
await getElixirVersions() await getElixirVersions()
const spec = exSpec0.replace(/-otp-.*$/, '') const spec = exSpec0.replace(otpSuffix, '')
const versions = elixirVersions const versions = elixirVersions
const elixirVersionFromSpec = getVersionFromSpec(spec, versions) const elixirVersionFromSpec = getVersionFromSpec(spec, versions)