Skip to content

Commit 15c7d05

Browse files
committed
Don't need sanitizeUrl()
1 parent ecc40f5 commit 15c7d05

2 files changed

Lines changed: 5 additions & 91 deletions

File tree

src/client/base.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -94,48 +94,18 @@ export class BaseIterableClient {
9494
return sanitized;
9595
};
9696

97-
const sanitizeUrl = (url?: string) => {
98-
if (!url) return url;
99-
try {
100-
// Use the actual base URL for realistic parsing context
101-
const baseUrl = clientConfig.baseUrl || "https://api.iterable.com";
102-
const urlObj = new URL(url, baseUrl);
103-
const sensitive = ["api_key", "apiKey", "token", "secret"];
104-
105-
let modified = false;
106-
sensitive.forEach(param => {
107-
if (urlObj.searchParams.has(param)) {
108-
urlObj.searchParams.set(param, "[REDACTED]");
109-
modified = true;
110-
}
111-
});
112-
113-
if (!modified) return url;
114-
115-
// If the input was an absolute URL, return the full sanitized URL
116-
if (/^https?:\/\//i.test(url)) {
117-
return urlObj.toString();
118-
}
119-
120-
// For relative URLs, return just the path and query components
121-
return urlObj.pathname + urlObj.search;
122-
} catch {
123-
return url;
124-
}
125-
};
126-
12797
this.client.interceptors.request.use((request) => {
12898
logger.debug("API request", {
12999
method: request.method?.toUpperCase(),
130-
url: sanitizeUrl(request.url),
100+
url: request.url,
131101
headers: sanitizeHeaders(request.headers),
132102
});
133103
return request;
134104
});
135105

136106
const createResponseLogData = (response: any, includeData = false) => ({
137107
status: response.status,
138-
url: sanitizeUrl(response.config?.url),
108+
url: response.config?.url,
139109
...(includeData && { data: response.data }),
140110
});
141111

tests/unit/sanitization.test.ts

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import axios from "axios";
55
jest.mock("axios");
66
const mockedAxios = axios as jest.Mocked<typeof axios>;
77

8+
import { BaseIterableClient } from "../../src/client/base.js";
89
// Import the real logger to spy on it
910
import { logger } from "../../src/logger.js";
10-
import { BaseIterableClient } from "../../src/client/base.js";
1111

1212
describe("Debug Logging Sanitization", () => {
1313
let mockClientInstance: any;
1414
let requestInterceptor: any;
15-
let responseInterceptorSuccess: any;
1615
let responseInterceptorError: any;
1716

1817
let debugSpy: any;
@@ -27,7 +26,6 @@ describe("Debug Logging Sanitization", () => {
2726
errorSpy = jest.spyOn(logger, "error").mockImplementation(() => logger);
2827

2928
requestInterceptor = undefined;
30-
responseInterceptorSuccess = undefined;
3129
responseInterceptorError = undefined;
3230

3331
mockClientInstance = {
@@ -40,7 +38,6 @@ describe("Debug Logging Sanitization", () => {
4038
},
4139
response: {
4240
use: jest.fn((success, error) => {
43-
responseInterceptorSuccess = success;
4441
responseInterceptorError = error;
4542
return 0;
4643
}),
@@ -102,59 +99,6 @@ describe("Debug Logging Sanitization", () => {
10299
);
103100
});
104101

105-
it("should redact sensitive query parameters in debug logs", () => {
106-
new BaseIterableClient({
107-
apiKey: "test-api-key",
108-
debug: true,
109-
baseUrl: "https://api.iterable.com",
110-
});
111-
112-
if (!requestInterceptor) throw new Error("Request interceptor missing");
113-
114-
const requestConfig = {
115-
method: "get",
116-
url: "https://api.iterable.com/test?apiKey=secret-key&token=secret-token&safe=value",
117-
};
118-
119-
requestInterceptor(requestConfig);
120-
121-
const logCall = debugSpy.mock.calls.find(
122-
(call: any) => call[0] === "API request"
123-
);
124-
125-
const logData = logCall?.[1] as any;
126-
const decodedUrl = decodeURIComponent(logData.url);
127-
expect(decodedUrl).toContain("apiKey=[REDACTED]");
128-
expect(decodedUrl).toContain("token=[REDACTED]");
129-
expect(decodedUrl).toContain("safe=value");
130-
});
131-
132-
it("should handle relative URLs in debug logs", () => {
133-
new BaseIterableClient({
134-
apiKey: "test-api-key",
135-
debug: true,
136-
baseUrl: "https://api.iterable.com",
137-
});
138-
139-
if (!requestInterceptor) throw new Error("Request interceptor missing");
140-
141-
const requestConfig = {
142-
method: "get",
143-
url: "/test?apiKey=secret-key&token=secret-token",
144-
};
145-
146-
requestInterceptor(requestConfig);
147-
148-
const logCall = debugSpy.mock.calls.find(
149-
(call: any) => call[0] === "API request"
150-
);
151-
152-
const logData = logCall?.[1] as any;
153-
const decodedUrl = decodeURIComponent(logData.url);
154-
expect(decodedUrl).toContain("/test?apiKey=[REDACTED]&token=[REDACTED]");
155-
expect(logData.url).not.toContain("https://");
156-
});
157-
158102
it("should NOT log error response data by default (debugVerbose=false)", async () => {
159103
new BaseIterableClient({
160104
apiKey: "test-api-key",
@@ -175,7 +119,7 @@ describe("Debug Logging Sanitization", () => {
175119

176120
try {
177121
await responseInterceptorError(errorResponse);
178-
} catch (e) {
122+
} catch {
179123
// Expected
180124
}
181125

@@ -214,7 +158,7 @@ describe("Debug Logging Sanitization", () => {
214158

215159
try {
216160
await responseInterceptorError(errorResponse);
217-
} catch (e) {
161+
} catch {
218162
// Expected
219163
}
220164

0 commit comments

Comments
 (0)