|
1 | 1 | import { dirname, join, resolve } from 'node:path'
|
2 | 2 | import fs from 'fs-extra'
|
3 | 3 | import { withLeadingSlash, withTrailingSlash } from 'ufo'
|
| 4 | +import { pick } from 'lodash-es' |
4 | 5 | import { useLogger, useUnlighthouse } from './unlighthouse'
|
5 |
| -import type { GenerateClientOptions, ResolvedUserConfig, RuntimeSettings, ScanMeta, UnlighthouseContext, UnlighthouseRouteReport } from './types' |
| 6 | +import type { |
| 7 | + ClientOptionsPayload, |
| 8 | + GenerateClientOptions, |
| 9 | + ScanMeta, |
| 10 | + UnlighthouseContext, |
| 11 | + UnlighthouseRouteReport, |
| 12 | +} from './types' |
6 | 13 | import { createScanMeta } from './data'
|
7 | 14 |
|
8 | 15 | /**
|
@@ -32,13 +39,35 @@ export async function generateClient(options: GenerateClientOptions = {}, unligh
|
32 | 39 | .replace(/(href|src)="\/assets\/(.*?)"/gm, `$1="${prefix}assets/$2"`)
|
33 | 40 | await fs.writeFile(resolve(runtimeSettings.generatedClientPath, 'index.html'), indexHTML, 'utf-8')
|
34 | 41 |
|
35 |
| - const staticData: { options: ResolvedUserConfig & RuntimeSettings; scanMeta: ScanMeta; reports: UnlighthouseRouteReport[] } = { |
| 42 | + const staticData: { options: ClientOptionsPayload; scanMeta: ScanMeta; reports: UnlighthouseRouteReport[] } = { |
36 | 43 | reports: [],
|
37 | 44 | scanMeta: createScanMeta(),
|
38 |
| - options: { ...runtimeSettings, ...resolvedConfig }, |
| 45 | + // need to be selective about what options we put here to avoid exposing anything sensitive |
| 46 | + options: pick({ |
| 47 | + ...runtimeSettings, |
| 48 | + ...resolvedConfig, |
| 49 | + }, [ |
| 50 | + 'client', |
| 51 | + 'site', |
| 52 | + 'websocketUrl', |
| 53 | + 'lighthouseOptions', |
| 54 | + 'scanner', |
| 55 | + 'routerPrefix', |
| 56 | + 'websocketUrl', |
| 57 | + 'apiUrl', |
| 58 | + ]), |
| 59 | + } |
| 60 | + // avoid exposing sensitive cookie / header options |
| 61 | + staticData.options.lighthouseOptions = { onlyCategories: resolvedConfig.lighthouseOptions.onlyCategories } |
| 62 | + if (options.static) { |
| 63 | + staticData.reports = worker.reports().map((r) => { |
| 64 | + return { |
| 65 | + ...r, |
| 66 | + // avoid exposing user paths |
| 67 | + artifactPath: '', |
| 68 | + } |
| 69 | + }) |
39 | 70 | }
|
40 |
| - if (options.static) |
41 |
| - staticData.reports = worker.reports() |
42 | 71 |
|
43 | 72 | await fs.writeFile(
|
44 | 73 | join(runtimeSettings.generatedClientPath, 'assets', 'payload.js'),
|
|
0 commit comments