@@ -8763,6 +8763,7 @@ const cacheUtils_1 = __nccwpck_require__(6017);
87638763const auth_1 = __nccwpck_require__(2492);
87648764const http_client_1 = __nccwpck_require__(944);
87658765const cache_twirp_client_1 = __nccwpck_require__(1208);
8766+ const util_1 = __nccwpck_require__(2718);
87668767/**
87678768 * This class is a wrapper around the CacheServiceClientJSON class generated by Twirp.
87688769 *
@@ -8822,7 +8823,7 @@ class CacheServiceClient {
88228823 (0, core_1.debug)(`[Response] - ${response.message.statusCode}`);
88238824 (0, core_1.debug)(`Headers: ${JSON.stringify(response.message.headers, null, 2)}`);
88248825 const body = JSON.parse(rawBody);
8825- this .maskSecretUrls(body);
8826+ (0, util_1 .maskSecretUrls) (body);
88268827 (0, core_1.debug)(`Body: ${JSON.stringify(body, null, 2)}`);
88278828 if (this.isSuccessStatusCode(statusCode)) {
88288829 return { response, body };
@@ -8863,36 +8864,6 @@ class CacheServiceClient {
88638864 throw new Error(`Request failed`);
88648865 });
88658866 }
8866- /**
8867- * Masks the `sig` parameter in a URL and sets it as a secret.
8868- * @param url The URL containing the `sig` parameter.
8869- * @returns A masked URL where the sig parameter value is replaced with '***' if found,
8870- * or the original URL if no sig parameter is present.
8871- */
8872- maskSigUrl(url) {
8873- const sigIndex = url.indexOf('sig=');
8874- if (sigIndex !== -1) {
8875- const sigValue = url.substring(sigIndex + 4);
8876- (0, core_1.setSecret)(sigValue);
8877- return `${url.substring(0, sigIndex + 4)}***`;
8878- }
8879- return url;
8880- }
8881- maskSecretUrls(body) {
8882- if (typeof body === 'object' && body !== null) {
8883- if ('signed_upload_url' in body &&
8884- typeof body.signed_upload_url === 'string') {
8885- this.maskSigUrl(body.signed_upload_url);
8886- }
8887- if ('signed_download_url' in body &&
8888- typeof body.signed_download_url === 'string') {
8889- this.maskSigUrl(body.signed_download_url);
8890- }
8891- }
8892- else {
8893- (0, core_1.debug)('body is not an object or is null');
8894- }
8895- }
88968867 isSuccessStatusCode(statusCode) {
88978868 if (!statusCode)
88988869 return false;
@@ -9035,6 +9006,151 @@ exports.getUserAgentString = getUserAgentString;
90359006
90369007/***/ }),
90379008
9009+ /***/ 2718:
9010+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
9011+
9012+ "use strict";
9013+
9014+ Object.defineProperty(exports, "__esModule", ({ value: true }));
9015+ exports.maskSecretUrls = exports.maskSigUrl = void 0;
9016+ const core_1 = __nccwpck_require__(9728);
9017+ /**
9018+ * Masks the `sig` parameter in a URL and sets it as a secret.
9019+ * @param url The URL containing the `sig` parameter.
9020+ * @returns A masked URL where the sig parameter value is replaced with '***' if found,
9021+ * or the original URL if no sig parameter is present.
9022+ */
9023+ function maskSigUrl(url) {
9024+ if (!url)
9025+ return url;
9026+ try {
9027+ const rawSigRegex = /[?&](sig)=([^&=#]+)/gi;
9028+ let match;
9029+ while ((match = rawSigRegex.exec(url)) !== null) {
9030+ const rawSignature = match[2];
9031+ if (rawSignature) {
9032+ (0, core_1.setSecret)(rawSignature);
9033+ }
9034+ }
9035+ let parsedUrl;
9036+ try {
9037+ parsedUrl = new URL(url);
9038+ }
9039+ catch (_a) {
9040+ try {
9041+ parsedUrl = new URL(url, 'https://example.com');
9042+ }
9043+ catch (error) {
9044+ (0, core_1.debug)(`Failed to parse URL: ${url}`);
9045+ return maskSigWithRegex(url);
9046+ }
9047+ }
9048+ let masked = false;
9049+ const paramNames = Array.from(parsedUrl.searchParams.keys());
9050+ for (const paramName of paramNames) {
9051+ if (paramName.toLowerCase() === 'sig') {
9052+ const signature = parsedUrl.searchParams.get(paramName);
9053+ if (signature) {
9054+ (0, core_1.setSecret)(signature);
9055+ (0, core_1.setSecret)(encodeURIComponent(signature));
9056+ parsedUrl.searchParams.set(paramName, '***');
9057+ masked = true;
9058+ }
9059+ }
9060+ }
9061+ if (masked) {
9062+ return parsedUrl.toString();
9063+ }
9064+ if (/([:?&]|^)(sig)=([^&=#]+)/i.test(url)) {
9065+ return maskSigWithRegex(url);
9066+ }
9067+ }
9068+ catch (error) {
9069+ (0, core_1.debug)(`Error masking URL: ${error instanceof Error ? error.message : String(error)}`);
9070+ return maskSigWithRegex(url);
9071+ }
9072+ return url;
9073+ }
9074+ exports.maskSigUrl = maskSigUrl;
9075+ /**
9076+ * Fallback method to mask signatures using regex when URL parsing fails
9077+ */
9078+ function maskSigWithRegex(url) {
9079+ try {
9080+ const regex = /([:?&]|^)(sig)=([^&=#]+)/gi;
9081+ return url.replace(regex, (fullMatch, prefix, paramName, value) => {
9082+ if (value) {
9083+ (0, core_1.setSecret)(value);
9084+ try {
9085+ (0, core_1.setSecret)(decodeURIComponent(value));
9086+ }
9087+ catch (_a) {
9088+ // Ignore decoding errors
9089+ }
9090+ return `${prefix}${paramName}=***`;
9091+ }
9092+ return fullMatch;
9093+ });
9094+ }
9095+ catch (error) {
9096+ (0, core_1.debug)(`Error in maskSigWithRegex: ${error instanceof Error ? error.message : String(error)}`);
9097+ return url;
9098+ }
9099+ }
9100+ /**
9101+ * Masks any URLs containing signature parameters in the provided object
9102+ * Recursively searches through nested objects and arrays
9103+ */
9104+ function maskSecretUrls(body) {
9105+ if (typeof body !== 'object' || body === null) {
9106+ (0, core_1.debug)('body is not an object or is null');
9107+ return;
9108+ }
9109+ const processUrl = (url) => {
9110+ maskSigUrl(url);
9111+ };
9112+ const processObject = (obj) => {
9113+ if (typeof obj !== 'object' || obj === null) {
9114+ return;
9115+ }
9116+ if (Array.isArray(obj)) {
9117+ for (const item of obj) {
9118+ if (typeof item === 'string') {
9119+ processUrl(item);
9120+ }
9121+ else if (typeof item === 'object' && item !== null) {
9122+ processObject(item);
9123+ }
9124+ }
9125+ return;
9126+ }
9127+ if ('signed_upload_url' in obj &&
9128+ typeof obj.signed_upload_url === 'string') {
9129+ maskSigUrl(obj.signed_upload_url);
9130+ }
9131+ if ('signed_download_url' in obj &&
9132+ typeof obj.signed_download_url === 'string') {
9133+ maskSigUrl(obj.signed_download_url);
9134+ }
9135+ for (const key in obj) {
9136+ const value = obj[key];
9137+ if (typeof value === 'string') {
9138+ if (/([:?&]|^)(sig)=/i.test(value)) {
9139+ maskSigUrl(value);
9140+ }
9141+ }
9142+ else if (typeof value === 'object' && value !== null) {
9143+ processObject(value);
9144+ }
9145+ }
9146+ };
9147+ processObject(body);
9148+ }
9149+ exports.maskSecretUrls = maskSecretUrls;
9150+ //# sourceMappingURL=util.js.map
9151+
9152+ /***/ }),
9153+
90389154/***/ 2043:
90399155/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
90409156
0 commit comments