Skip to content

Commit 160df0e

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[DrJones] redact cross-origin URLs
Fixed: 375546873 Change-Id: I50022cc3e86512a2562624349c9bcc690417b3b2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5965157 Reviewed-by: Mathias Bynens <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 86fe788 commit 160df0e

File tree

2 files changed

+74
-11
lines changed

2 files changed

+74
-11
lines changed

front_end/panels/freestyler/DrJonesNetworkAgent.test.ts

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {describeWithMockConnection} from '../../testing/MockConnection.js';
1515
import {createNetworkPanelForMockConnection} from '../../testing/NetworkHelpers.js';
1616
import * as Coordinator from '../../ui/components/render_coordinator/render_coordinator.js';
1717

18-
import {allowHeader, DrJonesNetworkAgent, ResponseType} from './freestyler.js';
18+
import {allowHeader, DrJonesNetworkAgent, formatInitiatorUrl, ResponseType} from './freestyler.js';
1919

2020
const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance();
2121

@@ -236,7 +236,7 @@ describeWithMockConnection('DrJonesNetworkAgent', () => {
236236
},
237237
{
238238
title: 'Request initiator chain',
239-
text: `- URL: https://www.initiator.com
239+
text: `- URL: <redacted cross-origin initiator URL>
240240
\t- URL: https://www.example.com
241241
\t\t- URL: https://www.example.com/1
242242
\t\t- URL: https://www.example.com/2`,
@@ -246,7 +246,7 @@ describeWithMockConnection('DrJonesNetworkAgent', () => {
246246
{
247247
type: ResponseType.QUERYING,
248248
query:
249-
'# Selected network request \nRequest: https://www.example.com\n\nRequest headers:\ncontent-type: bar1\n\nResponse headers:\ncontent-type: bar2\nx-forwarded-for: bar3\n\nResponse status: 200 \n\nRequest timing:\nQueued at (timestamp): 0 μs\nStarted at (timestamp): 8.3 min\nQueueing (duration): 8.3 min\nConnection start (stalled) (duration): 800.00 ms\nRequest sent (duration): 100.00 ms\nDuration (duration): 8.3 min\n\nRequest initiator chain:\n- URL: https://www.initiator.com\n\t- URL: https://www.example.com\n\t\t- URL: https://www.example.com/1\n\t\t- URL: https://www.example.com/2\n\n# User request\n\ntest',
249+
'# Selected network request \nRequest: https://www.example.com\n\nRequest headers:\ncontent-type: bar1\n\nResponse headers:\ncontent-type: bar2\nx-forwarded-for: bar3\n\nResponse status: 200 \n\nRequest timing:\nQueued at (timestamp): 0 μs\nStarted at (timestamp): 8.3 min\nQueueing (duration): 8.3 min\nConnection start (stalled) (duration): 800.00 ms\nRequest sent (duration): 100.00 ms\nDuration (duration): 8.3 min\n\nRequest initiator chain:\n- URL: <redacted cross-origin initiator URL>\n\t- URL: https://www.example.com\n\t\t- URL: https://www.example.com/1\n\t\t- URL: https://www.example.com/2\n\n# User request\n\ntest',
250250
},
251251
{
252252
type: ResponseType.ANSWER,
@@ -277,7 +277,7 @@ Request sent (duration): 100.00 ms
277277
Duration (duration): 8.3 min
278278
279279
Request initiator chain:
280-
- URL: https://www.initiator.com
280+
- URL: <redacted cross-origin initiator URL>
281281
\t- URL: https://www.example.com
282282
\t\t- URL: https://www.example.com/1
283283
\t\t- URL: https://www.example.com/2
@@ -305,4 +305,51 @@ test`,
305305
assert.isFalse(allowHeader({name: 'authorization', value: 'foo'}));
306306
});
307307
});
308+
309+
describe('formatInitiatorUrl', () => {
310+
const tests = [
311+
{
312+
allowedResource: 'https://example.test',
313+
targetResource: 'https://example.test',
314+
shouldBeRedacted: false,
315+
},
316+
{
317+
allowedResource: 'https://example.test',
318+
targetResource: 'https://another-example.test',
319+
shouldBeRedacted: true,
320+
},
321+
{
322+
allowedResource: 'file://test',
323+
targetResource: 'https://another-example.test',
324+
shouldBeRedacted: true,
325+
},
326+
{
327+
allowedResource: 'https://another-example.test',
328+
targetResource: 'file://test',
329+
shouldBeRedacted: true,
330+
},
331+
{
332+
allowedResource: 'https://test.example.test',
333+
targetResource: 'https://example.test',
334+
shouldBeRedacted: true,
335+
},
336+
{
337+
allowedResource: 'https://test.example.test:9900',
338+
targetResource: 'https://test.example.test:9901',
339+
shouldBeRedacted: true,
340+
},
341+
];
342+
343+
for (const t of tests) {
344+
it(`${t.targetResource} test when allowed resource is ${t.allowedResource}`, () => {
345+
const formatted = formatInitiatorUrl(new URL(t.targetResource).origin, new URL(t.allowedResource).origin);
346+
if (t.shouldBeRedacted) {
347+
assert.strictEqual(
348+
formatted, '<redacted cross-origin initiator URL>', `${JSON.stringify(t)} was not redacted`);
349+
} else {
350+
assert.strictEqual(formatted, t.targetResource, `${JSON.stringify(t)} was redacted`);
351+
}
352+
});
353+
}
354+
});
308355
});

front_end/panels/freestyler/DrJonesNetworkAgent.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,38 +324,54 @@ export function formatNetworkRequestTiming(request: SDK.NetworkRequest.NetworkRe
324324
return labels.filter(label => Boolean(label.value)).map(label => `${label.label}: ${label.value}`).join('\n');
325325
}
326326

327+
export function formatInitiatorUrl(initiatorUrl: string, allowedOrigin: string): string {
328+
const initiatorOrigin = new URL(initiatorUrl).origin;
329+
if (initiatorOrigin === allowedOrigin) {
330+
return initiatorUrl;
331+
}
332+
return '<redacted cross-origin initiator URL>';
333+
}
334+
327335
function formatRequestInitiated(
328-
request: SDK.NetworkRequest.NetworkRequest, initiatorChain: string, lineStart: string): string {
336+
request: SDK.NetworkRequest.NetworkRequest, initiatorChain: string, lineStart: string,
337+
allowedOrigin: string): string {
329338
const initiated = Logs.NetworkLog.NetworkLog.instance().initiatorGraphForRequest(request).initiated;
330339
initiated.forEach((v, initiatedRequest) => {
331340
if (request === v) {
332-
initiatorChain = initiatorChain + lineStart + initiatedRequest.url() + '\n';
333-
initiatorChain = formatRequestInitiated(initiatedRequest, initiatorChain, '\t' + lineStart);
341+
initiatorChain = initiatorChain + lineStart + formatInitiatorUrl(initiatedRequest.url(), allowedOrigin) + '\n';
342+
initiatorChain = formatRequestInitiated(initiatedRequest, initiatorChain, '\t' + lineStart, allowedOrigin);
334343
}
335344
});
336345
return initiatorChain;
337346
}
338347

348+
/**
349+
* Note: nothing here should include information from origins other than
350+
* the request's origin.
351+
*/
339352
function formatRequestInitiatorChain(request: SDK.NetworkRequest.NetworkRequest): string {
353+
const allowedOrigin = new URL(request.url()).origin;
340354
let initiatorChain = '';
341355
let lineStart = '- URL: ';
342356
const initiators = Logs.NetworkLog.NetworkLog.instance().initiatorGraphForRequest(request).initiators;
343357

344358
for (const initator of Array.from(initiators).reverse()) {
345-
initiatorChain = initiatorChain + lineStart + initator.url() + '\n';
359+
initiatorChain = initiatorChain + lineStart + formatInitiatorUrl(initator.url(), allowedOrigin) + '\n';
346360
lineStart = '\t' + lineStart;
347361
if (initator === request) {
348-
initiatorChain = formatRequestInitiated(initator, initiatorChain, lineStart);
362+
initiatorChain = formatRequestInitiated(initator, initiatorChain, lineStart, allowedOrigin);
349363
break;
350364
}
351365
}
352366

353367
return initiatorChain.trim();
354368
}
355369

370+
/**
371+
* Note: nothing here should include information from origins other than
372+
* the request's origin.
373+
*/
356374
export function formatNetworkRequest(request: SDK.NetworkRequest.NetworkRequest): string {
357-
// TODO: anything else that might be relavant?
358-
// TODO: handle missing headers
359375
return `Request: ${request.url()}
360376
361377
${formatHeaders('Request headers:', request.requestHeaders())}

0 commit comments

Comments
 (0)