Skip to content

Commit 65066e3

Browse files
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
1 parent 889e64e commit 65066e3

File tree

8 files changed

+24
-12
lines changed

8 files changed

+24
-12
lines changed

.github/workflows/action.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: action
33

4+
permissions:
5+
contents: read
6+
47
on:
58
push:
69
branches:
@@ -41,8 +44,6 @@ jobs:
4144
name: Expected local npm actions
4245
runs-on: ubuntu-latest
4346
if: github.ref != 'refs/heads/main'
44-
permissions:
45-
contents: read
4647
steps:
4748
- uses: actions/checkout@v4
4849
- uses: actions/setup-node@v4
@@ -56,8 +57,6 @@ jobs:
5657
name: Action
5758
runs-on: ubuntu-latest
5859
if: github.ref != 'refs/heads/main'
59-
permissions:
60-
contents: read
6160
steps:
6261
- uses: actions/checkout@v4
6362
- uses: raven-actions/actionlint@v2
@@ -94,8 +93,6 @@ jobs:
9493
unit_tests_macos:
9594
name: Unit tests (macOS)
9695
runs-on: macos-latest
97-
permissions:
98-
contents: read
9996
steps:
10097
- uses: actions/checkout@v4
10198
- uses: actions/setup-node@v4

.github/workflows/hexpm-mirrors.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: hexpm-mirrors
33

4+
permissions:
5+
contents: read
6+
47
on:
58
push:
69
branches:

.github/workflows/macos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
name: macos
3+
34
permissions:
45
contents: read
56

.github/workflows/ubuntu.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: ubuntu
33

4+
permissions:
5+
contents: read
6+
47
on:
58
push:
69
branches:

.github/workflows/update_3rd_party_licenses.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: Update 3rd party licenses (automation)
33

4+
permissions:
5+
contents: write
6+
47
on:
58
schedule:
69
- cron: '0 12 * * *'

.github/workflows/windows.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: windows
33

4+
permissions:
5+
contents: read
6+
47
on:
58
push:
69
branches:

dist/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26068,18 +26068,19 @@ function requestedVersionFor(tool, version, originListing, mirrors) {
2606826068
}
2606926069

2607026070
async function getElixirVersion(exSpec0, otpVersion0) {
26071-
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2]
26071+
const otpVersion = otpVersion0.match(/^(?:OTP-)?(.+)$/)[1]
2607226072
let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1]
2607326073

26074-
const userSuppliedOtp = exSpec0.match(/-otp-(\d+)/)?.[1] ?? null
26074+
const otpSuffix = /-otp-(\d+)/
26075+
const userSuppliedOtp = exSpec0.match(otpSuffix)?.[1] ?? null
2607526076

2607626077
if (userSuppliedOtp && isVersion(userSuppliedOtp)) {
2607726078
otpVersionMajor = userSuppliedOtp
2607826079
}
2607926080

2608026081
const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
2608126082
await getElixirVersions()
26082-
const spec = exSpec0.replace(/-otp-.*$/, '')
26083+
const spec = exSpec0.replace(otpSuffix, '')
2608326084
const versions = elixirVersions
2608426085
const elixirVersionFromSpec = getVersionFromSpec(spec, versions)
2608526086

src/setup-beam.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,19 @@ function requestedVersionFor(tool, version, originListing, mirrors) {
193193
}
194194

195195
async function getElixirVersion(exSpec0, otpVersion0) {
196-
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2]
196+
const otpVersion = otpVersion0.match(/^(?:OTP-)?(.+)$/)[1]
197197
let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1]
198198

199-
const userSuppliedOtp = exSpec0.match(/-otp-(\d+)/)?.[1] ?? null
199+
const otpSuffix = /-otp-(\d+)/
200+
const userSuppliedOtp = exSpec0.match(otpSuffix)?.[1] ?? null
200201

201202
if (userSuppliedOtp && isVersion(userSuppliedOtp)) {
202203
otpVersionMajor = userSuppliedOtp
203204
}
204205

205206
const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
206207
await getElixirVersions()
207-
const spec = exSpec0.replace(/-otp-.*$/, '')
208+
const spec = exSpec0.replace(otpSuffix, '')
208209
const versions = elixirVersions
209210
const elixirVersionFromSpec = getVersionFromSpec(spec, versions)
210211

0 commit comments

Comments
 (0)