@@ -8754,7 +8754,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8754
8754
});
8755
8755
};
8756
8756
Object.defineProperty(exports, "__esModule", ({ value: true }));
8757
- exports.internalCacheTwirpClient = exports.CacheServiceClient = void 0;
8757
+ exports.internalCacheTwirpClient = void 0;
8758
8758
const core_1 = __nccwpck_require__(9728);
8759
8759
const user_agent_1 = __nccwpck_require__(3909);
8760
8760
const errors_1 = __nccwpck_require__(1069);
@@ -8899,7 +8899,6 @@ class CacheServiceClient {
8899
8899
return Math.trunc(Math.random() * (maxTime - minTime) + minTime);
8900
8900
}
8901
8901
}
8902
- exports.CacheServiceClient = CacheServiceClient;
8903
8902
function internalCacheTwirpClient(options) {
8904
8903
const client = new CacheServiceClient((0, user_agent_1.getUserAgentString)(), options === null || options === void 0 ? void 0 : options.maxAttempts, options === null || options === void 0 ? void 0 : options.retryIntervalMs, options === null || options === void 0 ? void 0 : options.retryMultiplier);
8905
8904
return new cache_twirp_client_1.CacheServiceClientJSON(client);
@@ -9024,127 +9023,37 @@ function maskSigUrl(url) {
9024
9023
if (!url)
9025
9024
return url;
9026
9025
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) {
9026
+ const parsedUrl = new URL(url);
9027
+ const signature = parsedUrl.searchParams.get('sig');
9028
+ if (signature) {
9029
+ (0, core_1.setSecret)(signature);
9030
+ (0, core_1.setSecret)(encodeURIComponent(signature));
9031
+ parsedUrl.searchParams.set('sig', '***');
9062
9032
return parsedUrl.toString();
9063
9033
}
9064
- if (/([:?&]|^)(sig)=([^&=#]+)/i.test(url)) {
9065
- return maskSigWithRegex(url);
9066
- }
9067
9034
}
9068
9035
catch (error) {
9069
- (0, core_1.debug)(`Error masking URL: ${error instanceof Error ? error.message : String(error)}`);
9070
- return maskSigWithRegex(url);
9036
+ (0, core_1.debug)(`Failed to parse URL: ${url} ${error instanceof Error ? error.message : String(error)}`);
9071
9037
}
9072
9038
return url;
9073
9039
}
9074
9040
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
9041
/**
9101
9042
* Masks any URLs containing signature parameters in the provided object
9102
- * Recursively searches through nested objects and arrays
9103
9043
*/
9104
9044
function maskSecretUrls(body) {
9105
9045
if (typeof body !== 'object' || body === null) {
9106
9046
(0, core_1.debug)('body is not an object or is null');
9107
9047
return;
9108
9048
}
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);
9049
+ if ('signed_upload_url' in body &&
9050
+ typeof body.signed_upload_url === 'string') {
9051
+ maskSigUrl(body.signed_upload_url);
9052
+ }
9053
+ if ('signed_download_url' in body &&
9054
+ typeof body.signed_download_url === 'string') {
9055
+ maskSigUrl(body.signed_download_url);
9056
+ }
9148
9057
}
9149
9058
exports.maskSecretUrls = maskSecretUrls;
9150
9059
//# sourceMappingURL=util.js.map
0 commit comments