|
1 | 1 | import * as Effect from "effect/Effect"; |
2 | 2 | import * as Layer from "effect/Layer"; |
3 | | -import * as Tracer from "effect/Tracer"; |
4 | 3 | import * as Headers from "effect/http/Headers"; |
| 4 | +import * as UrlParams from "effect/http/UrlParams"; |
5 | 5 |
|
6 | | -export const layer = Layer.effect( |
7 | | - Headers.CurrentRedactedNames, |
8 | | - // `expo-session` carries the `eas login` session secret on Expo API requests. |
9 | | - Effect.map(Headers.CurrentRedactedNames, (names) => [...names, "dpop", "expo-session"]), |
| 6 | +export const layer = Layer.mergeAll( |
| 7 | + Layer.effect( |
| 8 | + Headers.CurrentRedactedNames, |
| 9 | + // `expo-session` carries the `eas login` session secret on Expo API requests. |
| 10 | + Effect.map(Headers.CurrentRedactedNames, (names) => [...names, "dpop", "expo-session"]), |
| 11 | + ), |
| 12 | + Layer.effect( |
| 13 | + UrlParams.CurrentRedactedNames, |
| 14 | + // Socket tickets and proofs, pairing tokens, and OAuth codes travel in query strings. |
| 15 | + Effect.map(UrlParams.CurrentRedactedNames, (names) => [ |
| 16 | + ...names, |
| 17 | + "wsTicket", |
| 18 | + "dpop", |
| 19 | + "token", |
| 20 | + "pairingUrl", |
| 21 | + "code", |
| 22 | + "state", |
| 23 | + "challenge", |
| 24 | + ]), |
| 25 | + ), |
10 | 26 | ); |
11 | | - |
12 | | -/** Query parameters that carry credentials: socket tickets and proofs, pairing tokens, OAuth codes. */ |
13 | | -const REDACTED_URL_PARAMS = /(^|[?&])(wsTicket|dpop|token|pairingUrl|code|state|challenge)=[^&#]*/g; |
14 | | - |
15 | | -const redactUrlAttribute = (key: string, value: unknown): unknown => |
16 | | - (key === "url.full" || key === "url.query") && typeof value === "string" |
17 | | - ? value.replace(REDACTED_URL_PARAMS, "$1$2=REDACTED") |
18 | | - : value; |
19 | | - |
20 | | -/** Effect's HTTP client and server spans record `url.full` and `url.query` verbatim. */ |
21 | | -export const redactUrlAttributes = (delegate: Tracer.Tracer): Tracer.Tracer => |
22 | | - Tracer.make({ |
23 | | - span(options) { |
24 | | - const span = delegate.span(options); |
25 | | - const attribute = span.attribute.bind(span); |
26 | | - span.attribute = (key, value) => attribute(key, redactUrlAttribute(key, value)); |
27 | | - return span; |
28 | | - }, |
29 | | - ...(delegate.context ? { context: delegate.context } : {}), |
30 | | - }); |
0 commit comments