fix: abort proxied requests when CONNECT does not return HTTP 200 (#2037)

* fix: abort proxied requests when CONNECT does not return HTTP 200

* chore: collapse error construction to satisfy biome formatter

---------

Co-authored-by: GitHub Actions <github-aws-sdk-osds-automation@amazon.com>
This commit is contained in:
Tom KellerandGitHub Actions authored and GitHub committed 2026-11-24 15:38:50 -08:00
1 parent 416c15366b
commit f9f13dcf7f
5 files changed
+190 -22

No files matched your search

+14
View File
@@ -1,4 +1,5 @@
import * as fs from 'node:fs';
import type * as http from 'node:http';
import * as path from 'node:path';
import * as core from '@actions/core';
import type { Credentials, STSClient } from '@aws-sdk/client-sts';
@@ -216,6 +217,19 @@ export function maskProxyCredentials(proxyServer: string): void {
}
}
// https-proxy-agent tunnels HTTPS requests through an HTTP proxy by issuing a
// CONNECT request. These requests should always return 200. A non-200 success
// reponse indicates proxy tampering or misconfiguration (or auth failure, but
// we abort anyway).
export function verifyProxyConnect(req: http.ClientRequest): void {
req.once('proxyConnect', (response: { statusCode: number; statusText: string }) => {
if (response.statusCode !== 200) {
const statusText = response.statusText ? ` ${response.statusText}` : '';
req.destroy(new Error(`Proxy CONNECT returned HTTP ${response.statusCode}${statusText}; aborting`));
}
});
}
// Tags have a more restrictive set of acceptable characters than GitHub environment variables can.
// This replaces anything not conforming to the tag restrictions by inverting the regular expression.
// See the AWS documentation for constraint specifics https://docs.aws.amazon.com/STS/latest/APIReference/API_Tag.html.