@@ -613,61 +613,25 @@ describe('request utils', () => {
613613 } ) ;
614614
615615 describe ( 'PII filtering' , ( ) => {
616- it ( 'filters out sensitive headers when sendDefaultPii is false (default)' , ( ) => {
617- const headers = {
618- 'Content-Type' : 'application/json' ,
619- 'User-Agent' : 'test-agent' ,
620- Authorization : 'Bearer secret-token' ,
621- Cookie : 'session=abc123' ,
622- 'X-API-Key' : 'api-key-123' ,
623- 'X-Auth-Token' : 'auth-token-456' ,
624- } ;
625-
626- const result = httpHeadersToSpanAttributes ( headers , false ) ;
627-
628- expect ( result ) . toEqual ( {
629- 'http.request.header.content_type' : 'application/json' ,
630- 'http.request.header.user_agent' : 'test-agent' ,
631- // Sensitive headers should be filtered out
632- } ) ;
633- } ) ;
634-
635- it ( 'includes sensitive headers when sendDefaultPii is true' , ( ) => {
636- const headers = {
637- 'Content-Type' : 'application/json' ,
638- 'User-Agent' : 'test-agent' ,
639- Authorization : 'Bearer secret-token' ,
640- Cookie : 'session=abc123' ,
641- 'X-API-Key' : 'api-key-123' ,
642- } ;
643-
644- const result = httpHeadersToSpanAttributes ( headers , true ) ;
645-
646- expect ( result ) . toEqual ( {
647- 'http.request.header.content_type' : 'application/json' ,
648- 'http.request.header.user_agent' : 'test-agent' ,
649- 'http.request.header.authorization' : 'Bearer secret-token' ,
650- 'http.request.header.cookie' : 'session=abc123' ,
651- 'http.request.header.x_api_key' : 'api-key-123' ,
652- } ) ;
653- } ) ;
654-
655616 it ( 'filters sensitive headers case-insensitively' , ( ) => {
656617 const headers = {
657618 AUTHORIZATION : 'Bearer secret-token' ,
658619 Cookie : 'session=abc123' ,
659- 'x-api-key ' : 'key-123' ,
620+ 'x-aPi-kEy ' : 'key-123' ,
660621 'Content-Type' : 'application/json' ,
661622 } ;
662623
663- const result = httpHeadersToSpanAttributes ( headers , false ) ;
624+ const result = httpHeadersToSpanAttributes ( headers ) ;
664625
665626 expect ( result ) . toEqual ( {
666627 'http.request.header.content_type' : 'application/json' ,
628+ 'http.request.header.cookie' : '[Filtered]' ,
629+ 'http.request.header.x_api_key' : '[Filtered]' ,
630+ 'http.request.header.authorization' : '[Filtered]' ,
667631 } ) ;
668632 } ) ;
669633
670- it ( 'filters comprehensive list of sensitive headers' , ( ) => {
634+ it ( 'always filters comprehensive list of sensitive headers' , ( ) => {
671635 const headers = {
672636 'Content-Type' : 'application/json' ,
673637 'User-Agent' : 'test-agent' ,
@@ -692,15 +656,41 @@ describe('request utils', () => {
692656 'X-Private-Key' : 'private' ,
693657 'X-Forwarded-user' : 'user' ,
694658 'X-Forwarded-authorization' : 'auth' ,
659+ 'x-jwt-token' : 'jwt' ,
660+ 'x-bearer-token' : 'bearer' ,
661+ 'x-sso-token' : 'sso' ,
662+ 'x-saml-token' : 'saml' ,
695663 } ;
696664
697- const result = httpHeadersToSpanAttributes ( headers , false ) ;
665+ const result = httpHeadersToSpanAttributes ( headers ) ;
698666
667+ // Sensitive headers are always included and redacted
699668 expect ( result ) . toEqual ( {
700669 'http.request.header.content_type' : 'application/json' ,
701670 'http.request.header.user_agent' : 'test-agent' ,
702671 'http.request.header.accept' : 'application/json' ,
703672 'http.request.header.host' : 'example.com' ,
673+ 'http.request.header.authorization' : '[Filtered]' ,
674+ 'http.request.header.cookie' : '[Filtered]' ,
675+ 'http.request.header.set_cookie' : '[Filtered]' ,
676+ 'http.request.header.x_api_key' : '[Filtered]' ,
677+ 'http.request.header.x_auth_token' : '[Filtered]' ,
678+ 'http.request.header.x_secret' : '[Filtered]' ,
679+ 'http.request.header.x_secret_key' : '[Filtered]' ,
680+ 'http.request.header.www_authenticate' : '[Filtered]' ,
681+ 'http.request.header.proxy_authorization' : '[Filtered]' ,
682+ 'http.request.header.x_access_token' : '[Filtered]' ,
683+ 'http.request.header.x_csrf_token' : '[Filtered]' ,
684+ 'http.request.header.x_xsrf_token' : '[Filtered]' ,
685+ 'http.request.header.x_session_token' : '[Filtered]' ,
686+ 'http.request.header.x_password' : '[Filtered]' ,
687+ 'http.request.header.x_private_key' : '[Filtered]' ,
688+ 'http.request.header.x_forwarded_user' : '[Filtered]' ,
689+ 'http.request.header.x_forwarded_authorization' : '[Filtered]' ,
690+ 'http.request.header.x_jwt_token' : '[Filtered]' ,
691+ 'http.request.header.x_bearer_token' : '[Filtered]' ,
692+ 'http.request.header.x_sso_token' : '[Filtered]' ,
693+ 'http.request.header.x_saml_token' : '[Filtered]' ,
704694 } ) ;
705695 } ) ;
706696 } ) ;
0 commit comments