Skip to content

Commit 983892b

Browse files
committed
Merge pull request #299 from shivammathur/fix_paths
Switch to environment files. Apply GHSA-mfwh-5m23-j46w (CVE-2020-15228)
2 parents 2a3920f + d07beb7 commit 983892b

File tree

7 files changed

+261
-162
lines changed

7 files changed

+261
-162
lines changed

dist/index.js

+84-19
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,32 @@ class ExecState extends events.EventEmitter {
953953

954954
/***/ }),
955955

956+
/***/ 82:
957+
/***/ (function(__unusedmodule, exports) {
958+
959+
"use strict";
960+
961+
// We use any as a valid input type
962+
/* eslint-disable @typescript-eslint/no-explicit-any */
963+
Object.defineProperty(exports, "__esModule", { value: true });
964+
/**
965+
* Sanitizes an input into a string so it can be passed into issueCommand safely
966+
* @param input input to sanitize into a string
967+
*/
968+
function toCommandValue(input) {
969+
if (input === null || input === undefined) {
970+
return '';
971+
}
972+
else if (typeof input === 'string' || input instanceof String) {
973+
return input;
974+
}
975+
return JSON.stringify(input);
976+
}
977+
exports.toCommandValue = toCommandValue;
978+
//# sourceMappingURL=utils.js.map
979+
980+
/***/ }),
981+
956982
/***/ 86:
957983
/***/ (function(__unusedmodule, exports, __webpack_require__) {
958984

@@ -1003,6 +1029,42 @@ module.exports = require("os");
10031029

10041030
/***/ }),
10051031

1032+
/***/ 102:
1033+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
1034+
1035+
"use strict";
1036+
1037+
// For internal use, subject to change.
1038+
var __importStar = (this && this.__importStar) || function (mod) {
1039+
if (mod && mod.__esModule) return mod;
1040+
var result = {};
1041+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1042+
result["default"] = mod;
1043+
return result;
1044+
};
1045+
Object.defineProperty(exports, "__esModule", { value: true });
1046+
// We use any as a valid input type
1047+
/* eslint-disable @typescript-eslint/no-explicit-any */
1048+
const fs = __importStar(__webpack_require__(747));
1049+
const os = __importStar(__webpack_require__(87));
1050+
const utils_1 = __webpack_require__(82);
1051+
function issueCommand(command, message) {
1052+
const filePath = process.env[`GITHUB_${command}`];
1053+
if (!filePath) {
1054+
throw new Error(`Unable to find environment variable for file command ${command}`);
1055+
}
1056+
if (!fs.existsSync(filePath)) {
1057+
throw new Error(`Missing file at path: ${filePath}`);
1058+
}
1059+
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
1060+
encoding: 'utf8'
1061+
});
1062+
}
1063+
exports.issueCommand = issueCommand;
1064+
//# sourceMappingURL=file-command.js.map
1065+
1066+
/***/ }),
1067+
10061068
/***/ 129:
10071069
/***/ (function(module) {
10081070

@@ -1348,6 +1410,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
13481410
};
13491411
Object.defineProperty(exports, "__esModule", { value: true });
13501412
const os = __importStar(__webpack_require__(87));
1413+
const utils_1 = __webpack_require__(82);
13511414
/**
13521415
* Commands
13531416
*
@@ -1401,28 +1464,14 @@ class Command {
14011464
return cmdStr;
14021465
}
14031466
}
1404-
/**
1405-
* Sanitizes an input into a string so it can be passed into issueCommand safely
1406-
* @param input input to sanitize into a string
1407-
*/
1408-
function toCommandValue(input) {
1409-
if (input === null || input === undefined) {
1410-
return '';
1411-
}
1412-
else if (typeof input === 'string' || input instanceof String) {
1413-
return input;
1414-
}
1415-
return JSON.stringify(input);
1416-
}
1417-
exports.toCommandValue = toCommandValue;
14181467
function escapeData(s) {
1419-
return toCommandValue(s)
1468+
return utils_1.toCommandValue(s)
14201469
.replace(/%/g, '%25')
14211470
.replace(/\r/g, '%0D')
14221471
.replace(/\n/g, '%0A');
14231472
}
14241473
function escapeProperty(s) {
1425-
return toCommandValue(s)
1474+
return utils_1.toCommandValue(s)
14261475
.replace(/%/g, '%25')
14271476
.replace(/\r/g, '%0D')
14281477
.replace(/\n/g, '%0A')
@@ -1456,6 +1505,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
14561505
};
14571506
Object.defineProperty(exports, "__esModule", { value: true });
14581507
const command_1 = __webpack_require__(431);
1508+
const file_command_1 = __webpack_require__(102);
1509+
const utils_1 = __webpack_require__(82);
14591510
const os = __importStar(__webpack_require__(87));
14601511
const path = __importStar(__webpack_require__(622));
14611512
/**
@@ -1482,9 +1533,17 @@ var ExitCode;
14821533
*/
14831534
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14841535
function exportVariable(name, val) {
1485-
const convertedVal = command_1.toCommandValue(val);
1536+
const convertedVal = utils_1.toCommandValue(val);
14861537
process.env[name] = convertedVal;
1487-
command_1.issueCommand('set-env', { name }, convertedVal);
1538+
const filePath = process.env['GITHUB_ENV'] || '';
1539+
if (filePath) {
1540+
const delimiter = '_GitHubActionsFileCommandDelimeter_';
1541+
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
1542+
file_command_1.issueCommand('ENV', commandValue);
1543+
}
1544+
else {
1545+
command_1.issueCommand('set-env', { name }, convertedVal);
1546+
}
14881547
}
14891548
exports.exportVariable = exportVariable;
14901549
/**
@@ -1500,7 +1559,13 @@ exports.setSecret = setSecret;
15001559
* @param inputPath
15011560
*/
15021561
function addPath(inputPath) {
1503-
command_1.issueCommand('add-path', {}, inputPath);
1562+
const filePath = process.env['GITHUB_PATH'] || '';
1563+
if (filePath) {
1564+
file_command_1.issueCommand('PATH', inputPath);
1565+
}
1566+
else {
1567+
command_1.issueCommand('add-path', {}, inputPath);
1568+
}
15041569
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
15051570
}
15061571
exports.addPath = addPath;

0 commit comments

Comments
 (0)