Skip to content

Commit cd81618

Browse files
ojuschugh1fatadel
authored andcommitted
Fix dev server rejecting non-localhost hosts when using FX_PROFILER_HOST (#5889)
1 parent e743aec commit cd81618

14 files changed

Lines changed: 211 additions & 34 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ If you'd like to use [profiler.firefox.com](https://profiler.firefox.com) via UR
9696
FX_PROFILER_HOST="0.0.0.0" yarn start
9797
```
9898

99-
You'll probably also want to add your non-localhost domains to the `allowedHosts` property in `server.js`.
99+
When using `FX_PROFILER_HOST="0.0.0.0"`, any hostname is allowed so you can access the profiler from other devices on your network. If you want to expose only a specific hostname instead, set `FX_PROFILER_HOST` to that hostname directly and it will be added to the allowed hosts automatically.
100100

101101
## Finding something to work on
102102

docs-developer/CHANGELOG-formats.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Note that this is not an exhaustive list. Processed profile format upgraders can
66

77
## Processed profile format
88

9+
### Version 62
10+
11+
A new `display` field of type `CounterDisplayConfig` was added to `RawCounter`.
12+
This metadata makes counters self-describing in terms of how they are rendered in the UI.
13+
For existing profiles, the display config is derived from the counter's `category` and `name`.
14+
915
### Version 61
1016

1117
The `SourceTable` in `profile.shared.sources` was updated:

scripts/lib/dev-server.mjs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@ const EXTRA_HEADERS = {
2626
// Allowed hosts for dev server
2727
const ALLOWED_HOSTS = ['localhost', '.app.github.dev'];
2828

29-
function isHostAllowed(hostHeader) {
29+
function isHostAllowed(hostHeader, boundHost) {
3030
if (!hostHeader) {
3131
return false;
3232
}
3333

34-
// Extract hostname without port
34+
// When binding to all interfaces, allow any host.
35+
if (boundHost === '0.0.0.0' || boundHost === '::' || boundHost === '::0') {
36+
return true;
37+
}
38+
3539
const hostname = hostHeader.split(':')[0];
40+
const allowedHosts = [...ALLOWED_HOSTS, boundHost];
3641

37-
// Check exact match or suffix match for wildcard patterns
38-
return ALLOWED_HOSTS.some((allowedHost) => {
42+
return allowedHosts.some((allowedHost) => {
3943
if (allowedHost.startsWith('.')) {
4044
// Wildcard pattern like '.app.github.dev'
4145
return hostname.endsWith(allowedHost);
@@ -75,7 +79,7 @@ export async function startDevServer(buildConfig, options = {}) {
7579
// Create HTTP server
7680
const server = http.createServer((req, res) => {
7781
// Validate Host header
78-
if (!isHostAllowed(req.headers.host)) {
82+
if (!isHostAllowed(req.headers.host, host)) {
7983
res.writeHead(403, { 'Content-Type': 'text/plain' });
8084
res.end('Invalid Host header');
8185
return;
@@ -86,7 +90,10 @@ export async function startDevServer(buildConfig, options = {}) {
8690
port: esbuildServerPort,
8791
path: req.url,
8892
method: req.method,
89-
headers: req.headers,
93+
headers: {
94+
...req.headers,
95+
host: hostname + ':' + esbuildServerPort,
96+
},
9097
};
9198

9299
// Forward each incoming request to esbuild

src/app-logic/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const GECKO_PROFILE_VERSION = 34;
1212
// The current version of the "processed" profile format.
1313
// Please don't forget to update the processed profile format changelog in
1414
// `docs-developer/CHANGELOG-formats.md`.
15-
export const PROCESSED_PROFILE_VERSION = 61;
15+
export const PROCESSED_PROFILE_VERSION = 62;
1616

1717
// The following are the margin sizes for the left and right of the timeline. Independent
1818
// components need to share these values.

src/profile-logic/process-profile.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import type {
9797
GeckoSourceTable,
9898
IndexIntoCategoryList,
9999
IndexIntoFrameTable,
100+
CounterDisplayConfig,
100101
} from 'firefox-profiler/types';
101102
import { decompress, isGzip } from 'firefox-profiler/utils/gz';
102103

@@ -972,6 +973,61 @@ function _processSamples(
972973
return samples;
973974
}
974975

976+
/**
977+
* Derive a CounterDisplayConfig from a counter's category and name.
978+
*/
979+
function _deriveCounterDisplay(
980+
category: string,
981+
name: string
982+
): CounterDisplayConfig {
983+
if (category === 'Memory') {
984+
return {
985+
graphType: 'line-accumulated',
986+
unit: 'bytes',
987+
color: 'orange',
988+
markerLocation: 'timeline-memory',
989+
sortOrder: 2,
990+
label: 'Memory',
991+
};
992+
} else if (category === 'power') {
993+
return {
994+
graphType: 'line-rate',
995+
unit: 'pWh',
996+
color: 'grey',
997+
markerLocation: null,
998+
sortOrder: 6,
999+
label: name,
1000+
};
1001+
} else if (category === 'Bandwidth') {
1002+
return {
1003+
graphType: 'line-rate',
1004+
unit: 'bytes',
1005+
color: 'blue',
1006+
markerLocation: null,
1007+
sortOrder: 8,
1008+
label: 'Bandwidth',
1009+
};
1010+
} else if (category === 'CPU' && name === 'processCPU') {
1011+
return {
1012+
graphType: 'line-rate',
1013+
unit: 'percent',
1014+
color: 'grey',
1015+
markerLocation: null,
1016+
sortOrder: 5,
1017+
label: 'Process CPU',
1018+
};
1019+
}
1020+
1021+
return {
1022+
graphType: 'line-rate',
1023+
unit: '',
1024+
color: 'grey',
1025+
markerLocation: null,
1026+
sortOrder: 9,
1027+
label: name,
1028+
};
1029+
}
1030+
9751031
/**
9761032
* Converts the Gecko list of counters into the processed format.
9771033
*/
@@ -1031,6 +1087,7 @@ function _processCounters(
10311087
pid: mainThreadPid,
10321088
mainThreadIndex,
10331089
samples: adjustTableTimeDeltas(processedCounterSamples, delta),
1090+
display: _deriveCounterDisplay(category, name),
10341091
});
10351092
return result;
10361093
},

src/profile-logic/processed-profile-versioning.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,66 @@ const _upgraders: {
30493049
}
30503050
},
30513051

3052+
[62]: (profile: any) => {
3053+
// Added CounterDisplayConfig to counters. This metadata controls how a
3054+
// counter is rendered (graph type, color, unit, etc.).
3055+
// Derive defaults from the counter's category and name.
3056+
if (profile.counters) {
3057+
for (const counter of profile.counters) {
3058+
if (counter.display !== undefined) {
3059+
continue;
3060+
}
3061+
const { category, name } = counter;
3062+
if (category === 'Memory') {
3063+
counter.display = {
3064+
graphType: 'line-accumulated',
3065+
unit: 'bytes',
3066+
color: 'orange',
3067+
markerLocation: 'timeline-memory',
3068+
sortOrder: 2,
3069+
label: 'Memory',
3070+
};
3071+
} else if (category === 'power') {
3072+
counter.display = {
3073+
graphType: 'line-rate',
3074+
unit: 'pWh',
3075+
color: 'grey',
3076+
markerLocation: null,
3077+
sortOrder: 6,
3078+
label: name,
3079+
};
3080+
} else if (category === 'Bandwidth') {
3081+
counter.display = {
3082+
graphType: 'line-rate',
3083+
unit: 'bytes',
3084+
color: 'blue',
3085+
markerLocation: null,
3086+
sortOrder: 8,
3087+
label: 'Bandwidth',
3088+
};
3089+
} else if (category === 'CPU' && name === 'processCPU') {
3090+
counter.display = {
3091+
graphType: 'line-rate',
3092+
unit: 'percent',
3093+
color: 'grey',
3094+
markerLocation: null,
3095+
sortOrder: 5,
3096+
label: 'Process CPU',
3097+
};
3098+
} else {
3099+
counter.display = {
3100+
graphType: 'line-rate',
3101+
unit: '',
3102+
color: 'grey',
3103+
markerLocation: null,
3104+
sortOrder: 9,
3105+
label: name,
3106+
};
3107+
}
3108+
}
3109+
}
3110+
},
3111+
30523112
// If you add a new upgrader here, please document the change in
30533113
// `docs-developer/CHANGELOG-formats.md`.
30543114
};

src/profile-logic/profile-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2307,7 +2307,7 @@ export function processCounter(rawCounter: RawCounter): Counter {
23072307
color: rawCounter.color,
23082308
pid: rawCounter.pid,
23092309
mainThreadIndex: rawCounter.mainThreadIndex,
2310-
2310+
display: rawCounter.display,
23112311
samples,
23122312
};
23132313

src/test/fixtures/profiles/processed-profile.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
CategoryList,
3434
JsTracerTable,
3535
RawCounter,
36+
CounterDisplayConfig,
3637
TabID,
3738
MarkerPayload,
3839
NetworkPayload,
@@ -1479,6 +1480,18 @@ export function getProfileWithJsTracerEvents(
14791480
return profile;
14801481
}
14811482

1483+
/**
1484+
* Default display configuration for test counters.
1485+
*/
1486+
const DEFAULT_TEST_COUNTER_DISPLAY: CounterDisplayConfig = {
1487+
graphType: 'line-rate',
1488+
unit: '',
1489+
color: 'grey',
1490+
markerLocation: null,
1491+
sortOrder: 9,
1492+
label: 'My Counter',
1493+
};
1494+
14821495
/**
14831496
* Creates a Counter fixture for a given thread.
14841497
*/
@@ -1504,6 +1517,7 @@ export function getCounterForThread(
15041517
count: sampleTimes.map((_, i) => Math.sin(i)),
15051518
length: thread.samples.length,
15061519
},
1520+
display: DEFAULT_TEST_COUNTER_DISPLAY,
15071521
};
15081522
return counter;
15091523
}
@@ -1541,6 +1555,7 @@ export function getCounterForThreadWithSamples(
15411555
pid: thread.pid,
15421556
mainThreadIndex,
15431557
samples: newSamples,
1558+
display: DEFAULT_TEST_COUNTER_DISPLAY,
15441559
};
15451560
return counter;
15461561
}

src/test/integration/symbolicator-cli/__snapshots__/symbolicator-cli.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Object {
8787
"markerSchema": Array [],
8888
"oscpu": "macOS 14.6.1",
8989
"pausedRanges": Array [],
90-
"preprocessedProfileVersion": 61,
90+
"preprocessedProfileVersion": 62,
9191
"processType": 0,
9292
"product": "a.out",
9393
"sampleUnits": Object {
@@ -1415,7 +1415,7 @@ Object {
14151415
"markerSchema": Array [],
14161416
"oscpu": "macOS 14.6.1",
14171417
"pausedRanges": Array [],
1418-
"preprocessedProfileVersion": 61,
1418+
"preprocessedProfileVersion": 62,
14191419
"processType": 0,
14201420
"product": "a.out",
14211421
"sampleUnits": Object {

src/test/store/__snapshots__/profile-view.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Object {
418418
"oscpu": "",
419419
"physicalCPUs": 0,
420420
"platform": "",
421-
"preprocessedProfileVersion": 61,
421+
"preprocessedProfileVersion": 62,
422422
"processType": 0,
423423
"product": "Firefox",
424424
"sourceURL": "",

0 commit comments

Comments
 (0)