Skip to content

Commit 4beda9c

Browse files
cory-millerthboop
andauthored
Merge pull request from GHSA-7r3h-m5j6-3q42
* use uuid as our multiline env delimiter * remove extra fn * Fix version * also throw error if delimiter is found in name or value * move delimiter and uuid to global var in test * upgrade uuid to newest version * remove spy variable * Update packages/core/src/core.ts Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com> * Update packages/core/src/core.ts Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com>
1 parent 90be12a commit 4beda9c

File tree

5 files changed

+92
-11
lines changed

5 files changed

+92
-11
lines changed

packages/core/RELEASES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# @actions/core Releases
22

3+
### 1.9.1
4+
- Randomize delimiter when calling `core.exportVariable`
5+
36
### 1.9.0
47
- Added `toPosixPath`, `toWin32Path` and `toPlatformPath` utilities [#1102](https://github.com/actions/toolkit/pull/1102)
58

packages/core/__tests__/core.test.ts

+41-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import * as path from 'path'
44
import * as core from '../src/core'
55
import {HttpClient} from '@actions/http-client'
66
import {toCommandProperties} from '../src/utils'
7+
import * as uuid from 'uuid'
8+
9+
jest.mock('uuid')
710

811
/* eslint-disable @typescript-eslint/unbound-method */
912

@@ -41,6 +44,9 @@ const testEnvVars = {
4144
GITHUB_ENV: ''
4245
}
4346

47+
const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
48+
const DELIMITER = `ghadelimiter_${UUID}`
49+
4450
describe('@actions/core', () => {
4551
beforeAll(() => {
4652
const filePath = path.join(__dirname, `test`)
@@ -54,6 +60,14 @@ describe('@actions/core', () => {
5460
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]
5561
}
5662
process.stdout.write = jest.fn()
63+
64+
jest.spyOn(uuid, 'v4').mockImplementation(() => {
65+
return UUID
66+
})
67+
})
68+
69+
afterEach(() => {
70+
jest.restoreAllMocks()
5771
})
5872

5973
it('legacy exportVariable produces the correct command and sets the env', () => {
@@ -91,7 +105,7 @@ describe('@actions/core', () => {
91105
core.exportVariable('my var', 'var val')
92106
verifyFileCommand(
93107
command,
94-
`my var<<_GitHubActionsFileCommandDelimeter_${os.EOL}var val${os.EOL}_GitHubActionsFileCommandDelimeter_${os.EOL}`
108+
`my var<<${DELIMITER}${os.EOL}var val${os.EOL}${DELIMITER}${os.EOL}`
95109
)
96110
})
97111

@@ -101,7 +115,7 @@ describe('@actions/core', () => {
101115
core.exportVariable('my var', true)
102116
verifyFileCommand(
103117
command,
104-
`my var<<_GitHubActionsFileCommandDelimeter_${os.EOL}true${os.EOL}_GitHubActionsFileCommandDelimeter_${os.EOL}`
118+
`my var<<${DELIMITER}${os.EOL}true${os.EOL}${DELIMITER}${os.EOL}`
105119
)
106120
})
107121

@@ -111,10 +125,34 @@ describe('@actions/core', () => {
111125
core.exportVariable('my var', 5)
112126
verifyFileCommand(
113127
command,
114-
`my var<<_GitHubActionsFileCommandDelimeter_${os.EOL}5${os.EOL}_GitHubActionsFileCommandDelimeter_${os.EOL}`
128+
`my var<<${DELIMITER}${os.EOL}5${os.EOL}${DELIMITER}${os.EOL}`
115129
)
116130
})
117131

132+
it('exportVariable does not allow delimiter as value', () => {
133+
const command = 'ENV'
134+
createFileCommandFile(command)
135+
136+
expect(() => {
137+
core.exportVariable('my var', `good stuff ${DELIMITER} bad stuff`)
138+
}).toThrow(`Unexpected input: value should not contain the delimiter "${DELIMITER}"`)
139+
140+
const filePath = path.join(__dirname, `test/${command}`)
141+
fs.unlinkSync(filePath)
142+
})
143+
144+
it('exportVariable does not allow delimiter as name', () => {
145+
const command = 'ENV'
146+
createFileCommandFile(command)
147+
148+
expect(() => {
149+
core.exportVariable(`good stuff ${DELIMITER} bad stuff`, 'test')
150+
}).toThrow(`Unexpected input: name should not contain the delimiter "${DELIMITER}"`)
151+
152+
const filePath = path.join(__dirname, `test/${command}`)
153+
fs.unlinkSync(filePath)
154+
})
155+
118156
it('setSecret produces the correct command', () => {
119157
core.setSecret('secret val')
120158
assertWriteCalls([`::add-mask::secret val${os.EOL}`])

packages/core/package-lock.json

+31-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/core",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "Actions core lib",
55
"keywords": [
66
"github",
@@ -36,9 +36,11 @@
3636
"url": "https://github.com/actions/toolkit/issues"
3737
},
3838
"dependencies": {
39-
"@actions/http-client": "^2.0.1"
39+
"@actions/http-client": "^2.0.1",
40+
"uuid": "^8.3.2"
4041
},
4142
"devDependencies": {
42-
"@types/node": "^12.0.2"
43+
"@types/node": "^12.0.2",
44+
"@types/uuid": "^8.3.4"
4345
}
4446
}

packages/core/src/core.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {toCommandProperties, toCommandValue} from './utils'
44

55
import * as os from 'os'
66
import * as path from 'path'
7+
import { v4 as uuidv4 } from 'uuid'
78

89
import {OidcClient} from './oidc-utils'
910

@@ -86,7 +87,17 @@ export function exportVariable(name: string, val: any): void {
8687

8788
const filePath = process.env['GITHUB_ENV'] || ''
8889
if (filePath) {
89-
const delimiter = '_GitHubActionsFileCommandDelimeter_'
90+
const delimiter = `ghadelimiter_${uuidv4()}`
91+
92+
// These should realistically never happen, but just in case someone finds a way to exploit uuid generation let's not allow keys or values that contain the delimiter.
93+
if (name.includes(delimiter)) {
94+
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`)
95+
}
96+
97+
if (convertedVal.includes(delimiter)) {
98+
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`)
99+
}
100+
90101
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`
91102
issueFileCommand('ENV', commandValue)
92103
} else {

0 commit comments

Comments
 (0)