@@ -231,6 +231,55 @@ function makeLinks(
231231}
232232
233233describe ( "EnvironmentConnector" , ( ) => {
234+ it ( "redacts endpoint secrets while preserving mapped causes" , ( ) => {
235+ const httpBaseUrl =
236+ "https://environment-user:[email protected] /private/workspace?access_token=environment-secret#environment-fragment" ; 237+ const cause = new Error ( "mint failed" ) ;
238+ const requestError = EnvironmentConnector . EnvironmentMintRequestFailed . fromEndpoint ( {
239+ userId : "user_123" ,
240+ environmentId : "env-connector-test" ,
241+ operation : "connect" ,
242+ stage : "send_request" ,
243+ httpBaseUrl,
244+ cause,
245+ } ) ;
246+ const responseError = EnvironmentConnector . EnvironmentMintResponseInvalid . fromEndpoint ( {
247+ userId : "user_123" ,
248+ environmentId : "env-connector-test" ,
249+ operation : "connect" ,
250+ httpBaseUrl,
251+ reason : "proof_verification_failed" ,
252+ cause,
253+ } ) ;
254+ const timeoutError = EnvironmentConnector . EnvironmentMintRequestTimedOut . fromEndpoint ( {
255+ userId : "user_123" ,
256+ environmentId : "env-connector-test" ,
257+ httpBaseUrl,
258+ timeoutMs : EnvironmentConnector . ENVIRONMENT_MINT_REQUEST_TIMEOUT_MS ,
259+ } ) ;
260+
261+ for ( const error of [ requestError , responseError , timeoutError ] ) {
262+ expect ( error ) . toMatchObject ( {
263+ httpBaseUrlInputLength : httpBaseUrl . length ,
264+ httpBaseUrlProtocol : "https:" ,
265+ httpBaseUrlHostname : "env.example.test" ,
266+ } ) ;
267+ const serialized = JSON . stringify ( error ) ;
268+ for ( const secret of [
269+ "environment-user" ,
270+ "environment-password" ,
271+ "/private/workspace" ,
272+ "environment-secret" ,
273+ "environment-fragment" ,
274+ ] ) {
275+ expect ( serialized ) . not . toContain ( secret ) ;
276+ expect ( error . message ) . not . toContain ( secret ) ;
277+ }
278+ }
279+ expect ( requestError . cause ) . toBe ( cause ) ;
280+ expect ( responseError . cause ) . toBe ( cause ) ;
281+ } ) ;
282+
234283 it . effect ( "loads the environment link and managed allocation concurrently" , ( ) =>
235284 Effect . gen ( function * ( ) {
236285 const started = yield * Ref . make ( 0 ) ;
@@ -405,24 +454,55 @@ describe("EnvironmentConnector", () => {
405454 const resolutionSpan = spans . find (
406455 ( span ) => span . name === "relay.environment_connector.resolve_managed_endpoint" ,
407456 ) ;
408- expect ( Object . fromEntries ( resolutionSpan ?. attributes ?? [ ] ) ) . toMatchObject ( {
457+ const resolutionAttributes = Object . fromEntries ( resolutionSpan ?. attributes ?? [ ] ) ;
458+ expect ( resolutionAttributes ) . toMatchObject ( {
409459 "relay.authorization.allocation_hostname" : "env.example.test" ,
410460 "relay.authorization.allocation_has_ready_at" : true ,
411461 "relay.authorization.allocation_has_tunnel_id" : true ,
412462 "relay.authorization.allocation_has_dns_record_id" : true ,
413- "relay.authorization.linked_http_base_url" : "https://attacker.example.test/" ,
414- "relay.authorization.linked_ws_base_url" : "wss://attacker.example.test/ws" ,
415- "relay.authorization.resolved_http_base_url" : "https://env.example.test/" ,
416- "relay.authorization.resolved_ws_base_url" : "wss://env.example.test/ws" ,
463+ "relay.authorization.linked_http_base_url.input_length" :
464+ "https://attacker-user:[email protected] /private/workspace?access_token=attacker-secret#attacker-fragment" 465+ . length ,
466+ "relay.authorization.linked_http_base_url.protocol" : "https:" ,
467+ "relay.authorization.linked_http_base_url.hostname" : "attacker.example.test" ,
468+ "relay.authorization.linked_ws_base_url.input_length" :
469+ "wss://socket-user:[email protected] /private/socket?access_token=socket-secret#socket-fragment" 470+ . length ,
471+ "relay.authorization.linked_ws_base_url.protocol" : "wss:" ,
472+ "relay.authorization.linked_ws_base_url.hostname" : "attacker.example.test" ,
473+ "relay.authorization.resolved_http_base_url.input_length" : "https://env.example.test/"
474+ . length ,
475+ "relay.authorization.resolved_http_base_url.protocol" : "https:" ,
476+ "relay.authorization.resolved_http_base_url.hostname" : "env.example.test" ,
477+ "relay.authorization.resolved_ws_base_url.input_length" : "wss://env.example.test/ws" . length ,
478+ "relay.authorization.resolved_ws_base_url.protocol" : "wss:" ,
479+ "relay.authorization.resolved_ws_base_url.hostname" : "env.example.test" ,
417480 } ) ;
481+ const serializedAttributes = JSON . stringify ( resolutionAttributes ) ;
482+ for ( const secret of [
483+ "attacker-user" ,
484+ "attacker-password" ,
485+ "/private/workspace" ,
486+ "attacker-secret" ,
487+ "attacker-fragment" ,
488+ "socket-user" ,
489+ "socket-password" ,
490+ "/private/socket" ,
491+ "socket-secret" ,
492+ "socket-fragment" ,
493+ ] ) {
494+ expect ( serializedAttributes ) . not . toContain ( secret ) ;
495+ }
418496 expect ( requestCount ) . toBe ( 0 ) ;
419497 } ) . pipe (
420498 Effect . provide (
421499 connectorTestLayer ( execute , {
422500 links : makeLinks ( {
423501 endpoint : {
424- httpBaseUrl : "https://attacker.example.test/" ,
425- wsBaseUrl : "wss://attacker.example.test/ws" ,
502+ httpBaseUrl :
503+ "https://attacker-user:[email protected] /private/workspace?access_token=attacker-secret#attacker-fragment" , 504+ wsBaseUrl :
505+ "wss://socket-user:[email protected] /private/socket?access_token=socket-secret#socket-fragment" , 426506 providerKind : "cloudflare_tunnel" ,
427507 } ,
428508 } ) ,
@@ -720,7 +800,9 @@ describe("EnvironmentConnector", () => {
720800 userId : "user_123" ,
721801 environmentId : "env-connector-test" ,
722802 operation : "connect" ,
723- httpBaseUrl : "https://env.example.test/" ,
803+ httpBaseUrlInputLength : "https://env.example.test/" . length ,
804+ httpBaseUrlProtocol : "https:" ,
805+ httpBaseUrlHostname : "env.example.test" ,
724806 reason : "proof_verification_failed" ,
725807 cause : { _tag : "RelayJwtError" } ,
726808 } ) ;
@@ -829,7 +911,9 @@ describe("EnvironmentConnector", () => {
829911 environmentId : "env-connector-test" ,
830912 operation : "connect" ,
831913 stage : "send_request" ,
832- httpBaseUrl : "https://env.example.test/" ,
914+ httpBaseUrlInputLength : "https://env.example.test/" . length ,
915+ httpBaseUrlProtocol : "https:" ,
916+ httpBaseUrlHostname : "env.example.test" ,
833917 deviceId : "device-123" ,
834918 cause : { _tag : "EnvironmentHttpInternalServerError" } ,
835919 } ) ;
@@ -870,7 +954,9 @@ describe("EnvironmentConnector", () => {
870954 expect ( result . failure ) . toMatchObject ( {
871955 userId : "user_123" ,
872956 environmentId : "env-connector-test" ,
873- httpBaseUrl : "https://env.example.test/" ,
957+ httpBaseUrlInputLength : "https://env.example.test/" . length ,
958+ httpBaseUrlProtocol : "https:" ,
959+ httpBaseUrlHostname : "env.example.test" ,
874960 timeoutMs : EnvironmentConnector . ENVIRONMENT_MINT_REQUEST_TIMEOUT_MS ,
875961 } ) ;
876962 }
0 commit comments