@@ -7174,14 +7174,28 @@ class Command {
71747174 return cmdStr;
71757175 }
71767176}
7177+ /**
7178+ * Sanitizes an input into a string so it can be passed into issueCommand safely
7179+ * @param input input to sanitize into a string
7180+ */
7181+ function toCommandValue(input) {
7182+ if (input === null || input === undefined) {
7183+ return '';
7184+ }
7185+ else if (typeof input === 'string' || input instanceof String) {
7186+ return input;
7187+ }
7188+ return JSON.stringify(input);
7189+ }
7190+ exports.toCommandValue = toCommandValue;
71777191function escapeData(s) {
7178- return (s || '' )
7192+ return toCommandValue(s )
71797193 .replace(/%/g, '%25')
71807194 .replace(/\r/g, '%0D')
71817195 .replace(/\n/g, '%0A');
71827196}
71837197function escapeProperty(s) {
7184- return (s || '' )
7198+ return toCommandValue(s )
71857199 .replace(/%/g, '%25')
71867200 .replace(/\r/g, '%0D')
71877201 .replace(/\n/g, '%0A')
@@ -9190,11 +9204,13 @@ var ExitCode;
91909204/**
91919205 * Sets env variable for this action and future actions in the job
91929206 * @param name the name of the variable to set
9193- * @param val the value of the variable
9207+ * @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify
91949208 */
9209+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91959210function exportVariable(name, val) {
9196- process.env[name] = val;
9197- command_1.issueCommand('set-env', { name }, val);
9211+ const convertedVal = command_1.toCommandValue(val);
9212+ process.env[name] = convertedVal;
9213+ command_1.issueCommand('set-env', { name }, convertedVal);
91989214}
91999215exports.exportVariable = exportVariable;
92009216/**
@@ -9233,12 +9249,22 @@ exports.getInput = getInput;
92339249 * Sets the value of an output.
92349250 *
92359251 * @param name name of the output to set
9236- * @param value value to store
9252+ * @param value value to store. Non-string values will be converted to a string via JSON.stringify
92379253 */
9254+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92389255function setOutput(name, value) {
92399256 command_1.issueCommand('set-output', { name }, value);
92409257}
92419258exports.setOutput = setOutput;
9259+ /**
9260+ * Enables or disables the echoing of commands into stdout for the rest of the step.
9261+ * Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.
9262+ *
9263+ */
9264+ function setCommandEcho(enabled) {
9265+ command_1.issue('echo', enabled ? 'on' : 'off');
9266+ }
9267+ exports.setCommandEcho = setCommandEcho;
92429268//-----------------------------------------------------------------------
92439269// Results
92449270//-----------------------------------------------------------------------
@@ -9272,18 +9298,18 @@ function debug(message) {
92729298exports.debug = debug;
92739299/**
92749300 * Adds an error issue
9275- * @param message error issue message
9301+ * @param message error issue message. Errors will be converted to string via toString()
92769302 */
92779303function error(message) {
9278- command_1.issue('error', message);
9304+ command_1.issue('error', message instanceof Error ? message.toString() : message );
92799305}
92809306exports.error = error;
92819307/**
92829308 * Adds an warning issue
9283- * @param message warning issue message
9309+ * @param message warning issue message. Errors will be converted to string via toString()
92849310 */
92859311function warning(message) {
9286- command_1.issue('warning', message);
9312+ command_1.issue('warning', message instanceof Error ? message.toString() : message );
92879313}
92889314exports.warning = warning;
92899315/**
@@ -9341,8 +9367,9 @@ exports.group = group;
93419367 * Saves state for current action, the state can only be retrieved by this action's post job execution.
93429368 *
93439369 * @param name name of the state to store
9344- * @param value value to store
9370+ * @param value value to store. Non-string values will be converted to a string via JSON.stringify
93459371 */
9372+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93469373function saveState(name, value) {
93479374 command_1.issueCommand('save-state', { name }, value);
93489375}
@@ -9694,6 +9721,7 @@ var HttpCodes;
96949721 HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
96959722 HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
96969723 HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
9724+ HttpCodes[HttpCodes["TooManyRequests"] = 429] = "TooManyRequests";
96979725 HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
96989726 HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
96999727 HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
@@ -9718,8 +9746,18 @@ function getProxyUrl(serverUrl) {
97189746 return proxyUrl ? proxyUrl.href : '';
97199747}
97209748exports.getProxyUrl = getProxyUrl;
9721- const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
9722- const HttpResponseRetryCodes = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout];
9749+ const HttpRedirectCodes = [
9750+ HttpCodes.MovedPermanently,
9751+ HttpCodes.ResourceMoved,
9752+ HttpCodes.SeeOther,
9753+ HttpCodes.TemporaryRedirect,
9754+ HttpCodes.PermanentRedirect
9755+ ];
9756+ const HttpResponseRetryCodes = [
9757+ HttpCodes.BadGateway,
9758+ HttpCodes.ServiceUnavailable,
9759+ HttpCodes.GatewayTimeout
9760+ ];
97239761const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
97249762const ExponentialBackoffCeiling = 10;
97259763const ExponentialBackoffTimeSlice = 5;
@@ -9844,18 +9882,22 @@ class HttpClient {
98449882 */
98459883 async request(verb, requestUrl, data, headers) {
98469884 if (this._disposed) {
9847- throw new Error(" Client has already been disposed." );
9885+ throw new Error(' Client has already been disposed.' );
98489886 }
98499887 let parsedUrl = url.parse(requestUrl);
98509888 let info = this._prepareRequest(verb, parsedUrl, headers);
98519889 // Only perform retries on reads since writes may not be idempotent.
9852- let maxTries = (this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1) ? this._maxRetries + 1 : 1;
9890+ let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1
9891+ ? this._maxRetries + 1
9892+ : 1;
98539893 let numTries = 0;
98549894 let response;
98559895 while (numTries < maxTries) {
98569896 response = await this.requestRaw(info, data);
98579897 // Check if it's an authentication challenge
9858- if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) {
9898+ if (response &&
9899+ response.message &&
9900+ response.message.statusCode === HttpCodes.Unauthorized) {
98599901 let authenticationHandler;
98609902 for (let i = 0; i < this.handlers.length; i++) {
98619903 if (this.handlers[i].canHandleAuthentication(response)) {
@@ -9873,21 +9915,32 @@ class HttpClient {
98739915 }
98749916 }
98759917 let redirectsRemaining = this._maxRedirects;
9876- while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1
9877- && this._allowRedirects
9878- && redirectsRemaining > 0) {
9879- const redirectUrl = response.message.headers[" location" ];
9918+ while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 &&
9919+ this._allowRedirects &&
9920+ redirectsRemaining > 0) {
9921+ const redirectUrl = response.message.headers[' location' ];
98809922 if (!redirectUrl) {
98819923 // if there's no location to redirect to, we won't
98829924 break;
98839925 }
98849926 let parsedRedirectUrl = url.parse(redirectUrl);
9885- if (parsedUrl.protocol == 'https:' && parsedUrl.protocol != parsedRedirectUrl.protocol && !this._allowRedirectDowngrade) {
9886- throw new Error("Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.");
9927+ if (parsedUrl.protocol == 'https:' &&
9928+ parsedUrl.protocol != parsedRedirectUrl.protocol &&
9929+ !this._allowRedirectDowngrade) {
9930+ throw new Error('Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.');
98879931 }
98889932 // we need to finish reading the response before reassigning response
98899933 // which will leak the open socket.
98909934 await response.readBody();
9935+ // strip authorization header if redirected to a different hostname
9936+ if (parsedRedirectUrl.hostname !== parsedUrl.hostname) {
9937+ for (let header in headers) {
9938+ // header names are case insensitive
9939+ if (header.toLowerCase() === 'authorization') {
9940+ delete headers[header];
9941+ }
9942+ }
9943+ }
98919944 // let's make the request with the new redirectUrl
98929945 info = this._prepareRequest(verb, parsedRedirectUrl, headers);
98939946 response = await this.requestRaw(info, data);
@@ -9938,8 +9991,8 @@ class HttpClient {
99389991 */
99399992 requestRawWithCallback(info, data, onResult) {
99409993 let socket;
9941- if (typeof ( data) === 'string') {
9942- info.options.headers[" Content-Length" ] = Buffer.byteLength(data, 'utf8');
9994+ if (typeof data === 'string') {
9995+ info.options.headers[' Content-Length' ] = Buffer.byteLength(data, 'utf8');
99439996 }
99449997 let callbackCalled = false;
99459998 let handleResult = (err, res) => {
@@ -9952,7 +10005,7 @@ class HttpClient {
995210005 let res = new HttpClientResponse(msg);
995310006 handleResult(null, res);
995410007 });
9955- req.on('socket', ( sock) => {
10008+ req.on('socket', sock => {
995610009 socket = sock;
995710010 });
995810011 // If we ever get disconnected, we want the socket to timeout eventually
@@ -9967,10 +10020,10 @@ class HttpClient {
996710020 // res should have headers
996810021 handleResult(err, null);
996910022 });
9970- if (data && typeof ( data) === 'string') {
10023+ if (data && typeof data === 'string') {
997110024 req.write(data, 'utf8');
997210025 }
9973- if (data && typeof ( data) !== 'string') {
10026+ if (data && typeof data !== 'string') {
997410027 data.on('close', function () {
997510028 req.end();
997610029 });
@@ -9997,31 +10050,34 @@ class HttpClient {
999710050 const defaultPort = usingSsl ? 443 : 80;
999810051 info.options = {};
999910052 info.options.host = info.parsedUrl.hostname;
10000- info.options.port = info.parsedUrl.port ? parseInt(info.parsedUrl.port) : defaultPort;
10001- info.options.path = (info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
10053+ info.options.port = info.parsedUrl.port
10054+ ? parseInt(info.parsedUrl.port)
10055+ : defaultPort;
10056+ info.options.path =
10057+ (info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
1000210058 info.options.method = method;
1000310059 info.options.headers = this._mergeHeaders(headers);
1000410060 if (this.userAgent != null) {
10005- info.options.headers[" user-agent" ] = this.userAgent;
10061+ info.options.headers[' user-agent' ] = this.userAgent;
1000610062 }
1000710063 info.options.agent = this._getAgent(info.parsedUrl);
1000810064 // gives handlers an opportunity to participate
1000910065 if (this.handlers) {
10010- this.handlers.forEach(( handler) => {
10066+ this.handlers.forEach(handler => {
1001110067 handler.prepareRequest(info.options);
1001210068 });
1001310069 }
1001410070 return info;
1001510071 }
1001610072 _mergeHeaders(headers) {
10017- const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
10073+ const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (( c[k.toLowerCase()] = obj[k]) , c), {});
1001810074 if (this.requestOptions && this.requestOptions.headers) {
1001910075 return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers));
1002010076 }
1002110077 return lowercaseKeys(headers || {});
1002210078 }
1002310079 _getExistingOrDefaultHeader(additionalHeaders, header, _default) {
10024- const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
10080+ const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (( c[k.toLowerCase()] = obj[k]) , c), {});
1002510081 let clientHeader;
1002610082 if (this.requestOptions && this.requestOptions.headers) {
1002710083 clientHeader = lowercaseKeys(this.requestOptions.headers)[header];
@@ -10059,7 +10115,7 @@ class HttpClient {
1005910115 proxyAuth: proxyUrl.auth,
1006010116 host: proxyUrl.hostname,
1006110117 port: proxyUrl.port
10062- },
10118+ }
1006310119 };
1006410120 let tunnelAgent;
1006510121 const overHttps = proxyUrl.protocol === 'https:';
@@ -10086,7 +10142,9 @@ class HttpClient {
1008610142 // we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
1008710143 // http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
1008810144 // we have to cast it to any and change it directly
10089- agent.options = Object.assign(agent.options || {}, { rejectUnauthorized: false });
10145+ agent.options = Object.assign(agent.options || {}, {
10146+ rejectUnauthorized: false
10147+ });
1009010148 }
1009110149 return agent;
1009210150 }
@@ -10147,7 +10205,7 @@ class HttpClient {
1014710205 msg = contents;
1014810206 }
1014910207 else {
10150- msg = " Failed request: (" + statusCode + ")" ;
10208+ msg = ' Failed request: (' + statusCode + ')' ;
1015110209 }
1015210210 let err = new Error(msg);
1015310211 // attach statusCode and body obj (if available) to the error object
@@ -27832,12 +27890,10 @@ function getProxyUrl(reqUrl) {
2783227890 }
2783327891 let proxyVar;
2783427892 if (usingSsl) {
27835- proxyVar = process.env["https_proxy"] ||
27836- process.env["HTTPS_PROXY"];
27893+ proxyVar = process.env['https_proxy'] || process.env['HTTPS_PROXY'];
2783727894 }
2783827895 else {
27839- proxyVar = process.env["http_proxy"] ||
27840- process.env["HTTP_PROXY"];
27896+ proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY'];
2784127897 }
2784227898 if (proxyVar) {
2784327899 proxyUrl = url.parse(proxyVar);
@@ -27849,7 +27905,7 @@ function checkBypass(reqUrl) {
2784927905 if (!reqUrl.hostname) {
2785027906 return false;
2785127907 }
27852- let noProxy = process.env[" no_proxy" ] || process.env[" NO_PROXY" ] || '';
27908+ let noProxy = process.env[' no_proxy' ] || process.env[' NO_PROXY' ] || '';
2785327909 if (!noProxy) {
2785427910 return false;
2785527911 }
@@ -27870,7 +27926,10 @@ function checkBypass(reqUrl) {
2787027926 upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
2787127927 }
2787227928 // Compare request host against noproxy
27873- for (let upperNoProxyItem of noProxy.split(',').map(x => x.trim().toUpperCase()).filter(x => x)) {
27929+ for (let upperNoProxyItem of noProxy
27930+ .split(',')
27931+ .map(x => x.trim().toUpperCase())
27932+ .filter(x => x)) {
2787427933 if (upperReqHosts.some(x => x === upperNoProxyItem)) {
2787527934 return true;
2787627935 }
0 commit comments