@datadog/mobile-react-native 3.11.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/android/build.gradle +14 -5
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/datadog-configuration.gradle +59 -18
- package/datadog-configuration.schema.json +119 -0
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +6 -1
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/config/FileBasedConfiguration.js +2 -0
- package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
- package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +2 -1
- package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
- package/lib/commonjs/config/features/RumConfiguration.js +4 -0
- package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
- package/lib/commonjs/flags/DdFlags.js +4 -2
- package/lib/commonjs/flags/DdFlags.js.map +1 -1
- package/lib/commonjs/flags/FlagsClient.js +4 -2
- package/lib/commonjs/flags/FlagsClient.js.map +1 -1
- package/lib/commonjs/internal.js +97 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/logs/DdLogs.js +4 -2
- package/lib/commonjs/logs/DdLogs.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +4 -2
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
- package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
- package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
- package/lib/commonjs/specs/NativeDdFlags.js +19 -3
- package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
- package/lib/commonjs/specs/NativeDdLogs.js +19 -3
- package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
- package/lib/commonjs/specs/NativeDdRum.js +19 -3
- package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
- package/lib/commonjs/specs/NativeDdSdk.js +19 -3
- package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
- package/lib/commonjs/specs/NativeDdTrace.js +19 -3
- package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
- package/lib/commonjs/trace/DdTrace.js +4 -2
- package/lib/commonjs/trace/DdTrace.js.map +1 -1
- package/lib/commonjs/utils/stringUtils.js +48 -0
- package/lib/commonjs/utils/stringUtils.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +6 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/config/FileBasedConfiguration.js +2 -0
- package/lib/module/config/FileBasedConfiguration.js.map +1 -1
- package/lib/module/config/async/AutoInstrumentationConfiguration.js +2 -1
- package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
- package/lib/module/config/features/RumConfiguration.js +4 -0
- package/lib/module/config/features/RumConfiguration.js.map +1 -1
- package/lib/module/flags/DdFlags.js +4 -2
- package/lib/module/flags/DdFlags.js.map +1 -1
- package/lib/module/flags/FlagsClient.js +5 -2
- package/lib/module/flags/FlagsClient.js.map +1 -1
- package/lib/module/internal.js +27 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/logs/DdLogs.js +4 -2
- package/lib/module/logs/DdLogs.js.map +1 -1
- package/lib/module/rum/DdRum.js +4 -2
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
- package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
- package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
- package/lib/module/sdk/DdSdkInternal.js +27 -22
- package/lib/module/sdk/DdSdkInternal.js.map +1 -1
- package/lib/module/specs/NativeDdFlags.js +14 -2
- package/lib/module/specs/NativeDdFlags.js.map +1 -1
- package/lib/module/specs/NativeDdLogs.js +14 -2
- package/lib/module/specs/NativeDdLogs.js.map +1 -1
- package/lib/module/specs/NativeDdRum.js +14 -2
- package/lib/module/specs/NativeDdRum.js.map +1 -1
- package/lib/module/specs/NativeDdSdk.js +14 -2
- package/lib/module/specs/NativeDdSdk.js.map +1 -1
- package/lib/module/specs/NativeDdTrace.js +14 -2
- package/lib/module/specs/NativeDdTrace.js.map +1 -1
- package/lib/module/trace/DdTrace.js +4 -2
- package/lib/module/trace/DdTrace.js.map +1 -1
- package/lib/module/utils/stringUtils.js +42 -0
- package/lib/module/utils/stringUtils.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/FileBasedConfiguration.type.d.ts +2 -0
- package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +3 -0
- package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/features/RumConfiguration.d.ts +3 -1
- package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/features/RumConfiguration.type.d.ts +107 -0
- package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
- package/lib/typescript/flags/FlagsClient.d.ts +1 -1
- package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/internal.d.ts +26 -0
- package/lib/typescript/internal.d.ts.map +1 -0
- package/lib/typescript/logs/DdLogs.d.ts +1 -1
- package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
- package/lib/typescript/rum/DdRum.d.ts +1 -1
- package/lib/typescript/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
- package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
- package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
- package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
- package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdRum.d.ts +7 -2
- package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
- package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
- package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
- package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
- package/lib/typescript/utils/stringUtils.d.ts +12 -0
- package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +7 -2
- package/src/DdSdkReactNative.tsx +11 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
- package/src/__tests__/internalEntry.test.ts +26 -0
- package/src/__tests__/mock.test.ts +1 -3
- package/src/__tests__/nativeSpecGetters.test.ts +102 -0
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
- package/src/__tests__/wrapperImportSafety.test.ts +129 -0
- package/src/config/FileBasedConfiguration.ts +3 -0
- package/src/config/FileBasedConfiguration.type.ts +2 -0
- package/src/config/__tests__/FileBasedConfiguration.test.ts +66 -0
- package/src/config/__tests__/__fixtures__/configuration-all-fields.json +8 -0
- package/src/config/async/AutoInstrumentationConfiguration.ts +5 -1
- package/src/config/features/RumConfiguration.ts +9 -0
- package/src/config/features/RumConfiguration.type.ts +117 -0
- package/src/flags/DdFlags.ts +4 -3
- package/src/flags/FlagsClient.ts +4 -3
- package/src/index.tsx +7 -0
- package/src/internal.ts +32 -0
- package/src/logs/DdLogs.ts +4 -3
- package/src/rum/DdRum.ts +4 -3
- package/src/rum/__tests__/DdRum.test.ts +4 -4
- package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
- package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
- package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
- package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
- package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +21 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +274 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +34 -3
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +624 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +6 -1
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
- package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
- package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
- package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -1
- package/src/sdk/DdSdkInternal.ts +27 -24
- package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
- package/src/specs/NativeDdFlags.ts +14 -2
- package/src/specs/NativeDdLogs.ts +14 -2
- package/src/specs/NativeDdRum.ts +14 -2
- package/src/specs/NativeDdSdk.ts +14 -2
- package/src/specs/NativeDdTrace.ts +14 -2
- package/src/trace/DdTrace.ts +4 -3
- package/src/utils/__tests__/stringUtils.test.ts +90 -0
- package/src/utils/stringUtils.ts +41 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { InternalLog } from '../../../../InternalLog';
|
|
8
|
+
import type { HeaderCaptureRule } from '../../../../config/features/RumConfiguration.type';
|
|
9
|
+
import { SdkVerbosity } from '../../../../config/types/SdkVerbosity';
|
|
10
|
+
import { escapeRegExp } from '../distributedTracing/firstPartyHosts';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_REQUEST_HEADERS,
|
|
14
|
+
DEFAULT_RESPONSE_HEADERS,
|
|
15
|
+
CANONICAL_REQUEST_HEADERS,
|
|
16
|
+
CANONICAL_RESPONSE_HEADERS
|
|
17
|
+
} from './captureHeaders';
|
|
18
|
+
import { normalizeHostname } from './normalizeUrlForMatching';
|
|
19
|
+
import type {
|
|
20
|
+
CompiledHeaderCaptureConfig,
|
|
21
|
+
CompiledHeaderCaptureRule
|
|
22
|
+
} from './types';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Builds a URL-matching RegExp from a user-supplied `match` string.
|
|
26
|
+
*
|
|
27
|
+
* The regex is applied to full URL strings (e.g. "https://api.example.com/v2/users").
|
|
28
|
+
* Pattern: `^https?://([^/?#\\]*@)?([^/?#@:\\]+\.)?${escapedHost}(:\d+)?${pathSuffix}`
|
|
29
|
+
* Optional userinfo (`user:pass@`) is allowed before the host; a hostname that
|
|
30
|
+
* only appears in the userinfo never matches.
|
|
31
|
+
* Subdomains are restricted to hostname characters, so a hostname appearing in
|
|
32
|
+
* the path or query of another URL never matches. Backslashes are excluded too,
|
|
33
|
+
* as URL parsers treat them as path separators. The path prefix (if any) must
|
|
34
|
+
* end on a path segment boundary: `api.example.com/v2` matches `/v2` and `/v2/users`,
|
|
35
|
+
* but not `/v22`. The host is matched case-insensitively (URLs go through
|
|
36
|
+
* normalizeUrlForMatching first), the path prefix case-sensitively.
|
|
37
|
+
*
|
|
38
|
+
* Returns null if the pattern is invalid (e.g. contains unescaped regex metacharacters that
|
|
39
|
+
* result in an invalid expression).
|
|
40
|
+
*/
|
|
41
|
+
const buildUrlMatchRegex = (match: string): RegExp | null => {
|
|
42
|
+
if (match === '*') {
|
|
43
|
+
return /.*/;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Split on first '/' to separate hostname from optional path prefix
|
|
47
|
+
const slashIndex = match.indexOf('/');
|
|
48
|
+
const hostname = slashIndex === -1 ? match : match.slice(0, slashIndex);
|
|
49
|
+
const pathPrefix = slashIndex === -1 ? '' : match.slice(slashIndex);
|
|
50
|
+
|
|
51
|
+
// The pattern host goes through the same normalizeHostname as request URLs
|
|
52
|
+
// (normalizeUrlForMatching), so hosts match case-insensitively. Paths stay case-sensitive.
|
|
53
|
+
const escapedHost = escapeRegExp(normalizeHostname(hostname));
|
|
54
|
+
// Host and path prefix must be followed by /, ?, # or end-of-string.
|
|
55
|
+
// A path prefix ending with '/' is already on a segment boundary.
|
|
56
|
+
const boundary = '(/|\\?|#|$)';
|
|
57
|
+
const pathSuffix = pathPrefix.endsWith('/')
|
|
58
|
+
? escapeRegExp(pathPrefix)
|
|
59
|
+
: `${escapeRegExp(pathPrefix)}${boundary}`;
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
// Regex matches full URL strings: scheme + optional userinfo + optional subdomains + host + optional port + path
|
|
63
|
+
const regex = new RegExp(
|
|
64
|
+
`^https?://([^/?#\\\\]*@)?([^/?#@:\\\\]+\\.)?${escapedHost}(:\\d+)?${pathSuffix}`
|
|
65
|
+
);
|
|
66
|
+
// Validate the final regex is well-formed
|
|
67
|
+
regex.test('validation_probe');
|
|
68
|
+
return regex;
|
|
69
|
+
} catch (_e) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Result from building a forURLs regex, carrying both the compiled regex
|
|
76
|
+
* and whether it represents a scoped (specific URL patterns) or catch-all match.
|
|
77
|
+
*/
|
|
78
|
+
type ForURLsResult = { regex: RegExp; isScoped: boolean } | null | 'skip';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Builds a combined URL-matching RegExp from an array of `forURLs` patterns.
|
|
82
|
+
*
|
|
83
|
+
* Returns an object with `regex` and `isScoped`, or `null` (all invalid), or `'skip'` (empty array).
|
|
84
|
+
* - `undefined` or `['*']` -> catch-all, isScoped=false
|
|
85
|
+
* - `[]` -> 'skip'
|
|
86
|
+
* - Specific patterns -> combined regex, isScoped=true
|
|
87
|
+
*/
|
|
88
|
+
const buildForURLsRegex = (forURLs: string[] | undefined): ForURLsResult => {
|
|
89
|
+
// Omitting forURLs = match all URLs (catch-all)
|
|
90
|
+
if (forURLs === undefined) {
|
|
91
|
+
return { regex: /.*/, isScoped: false };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Empty array = no-op rule, skip with warning
|
|
95
|
+
if (forURLs.length === 0) {
|
|
96
|
+
return 'skip';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Any array containing '*' matches all URLs, so it is equivalent to
|
|
100
|
+
// omitting forURLs (catch-all)
|
|
101
|
+
if (forURLs.includes('*')) {
|
|
102
|
+
return { regex: /.*/, isScoped: false };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Specific patterns = scoped
|
|
106
|
+
const patterns: string[] = [];
|
|
107
|
+
for (const pattern of forURLs) {
|
|
108
|
+
const regex = buildUrlMatchRegex(pattern);
|
|
109
|
+
if (regex === null) {
|
|
110
|
+
InternalLog.log(
|
|
111
|
+
`[DatadogRUM] headerCaptureRules: Skipping invalid forURLs pattern "${pattern}".`,
|
|
112
|
+
SdkVerbosity.WARN
|
|
113
|
+
);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
// Extract the source from the compiled regex to combine
|
|
117
|
+
patterns.push(regex.source);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (patterns.length === 0) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
return { regex: new RegExp(patterns.join('|')), isScoped: true };
|
|
126
|
+
} catch (_e) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const isStringArray = (value: unknown): value is string[] =>
|
|
132
|
+
Array.isArray(value) && value.every(item => typeof item === 'string');
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Checks the shape of a user-supplied rule at runtime. Rules coming from
|
|
136
|
+
* file-based configuration are not type-checked, so malformed entries must
|
|
137
|
+
* be skipped instead of throwing during compilation.
|
|
138
|
+
*/
|
|
139
|
+
const getRuleValidationError = (rule: unknown): string | null => {
|
|
140
|
+
if (typeof rule !== 'object' || rule === null) {
|
|
141
|
+
return 'rule is not an object';
|
|
142
|
+
}
|
|
143
|
+
const { type, headers, forURLs } = rule as Record<string, unknown>;
|
|
144
|
+
if (forURLs !== undefined && !isStringArray(forURLs)) {
|
|
145
|
+
return '`forURLs` must be an array of strings';
|
|
146
|
+
}
|
|
147
|
+
switch (type) {
|
|
148
|
+
case 'defaults':
|
|
149
|
+
return null;
|
|
150
|
+
case 'matchHeaders':
|
|
151
|
+
case 'matchRequestHeaders':
|
|
152
|
+
case 'matchResponseHeaders':
|
|
153
|
+
return isStringArray(headers)
|
|
154
|
+
? null
|
|
155
|
+
: '`headers` must be an array of strings';
|
|
156
|
+
default:
|
|
157
|
+
// Only interpolate strings: arbitrary objects may not be convertible
|
|
158
|
+
return typeof type === 'string'
|
|
159
|
+
? `unknown type "${type}"`
|
|
160
|
+
: '`type` must be a string';
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Compiles an array of composable `HeaderCaptureRule` entries into compiled rules.
|
|
166
|
+
* Each rule variant type produces a different set of request/response header names.
|
|
167
|
+
* Each compiled rule carries an `isScoped` flag from its forURLs resolution.
|
|
168
|
+
*/
|
|
169
|
+
const compileRules = (rules: unknown[]): CompiledHeaderCaptureRule[] => {
|
|
170
|
+
const compiled: CompiledHeaderCaptureRule[] = [];
|
|
171
|
+
|
|
172
|
+
for (const candidate of rules) {
|
|
173
|
+
const validationError = getRuleValidationError(candidate);
|
|
174
|
+
if (validationError !== null) {
|
|
175
|
+
InternalLog.log(
|
|
176
|
+
`[DatadogRUM] headerCaptureRules: Skipping invalid rule (${validationError}).`,
|
|
177
|
+
SdkVerbosity.WARN
|
|
178
|
+
);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const rule = candidate as HeaderCaptureRule;
|
|
182
|
+
|
|
183
|
+
// Build URL regex from forURLs
|
|
184
|
+
const urlResult = buildForURLsRegex(rule.forURLs);
|
|
185
|
+
|
|
186
|
+
if (urlResult === 'skip') {
|
|
187
|
+
InternalLog.log(
|
|
188
|
+
'[DatadogRUM] headerCaptureRules: Skipping rule with empty forURLs array (no-op).',
|
|
189
|
+
SdkVerbosity.WARN
|
|
190
|
+
);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (urlResult === null) {
|
|
195
|
+
InternalLog.log(
|
|
196
|
+
'[DatadogRUM] headerCaptureRules: Skipping rule — all forURLs patterns are invalid.',
|
|
197
|
+
SdkVerbosity.WARN
|
|
198
|
+
);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const { regex: urlRegex, isScoped } = urlResult;
|
|
203
|
+
|
|
204
|
+
switch (rule.type) {
|
|
205
|
+
case 'defaults':
|
|
206
|
+
compiled.push({
|
|
207
|
+
urlRegex,
|
|
208
|
+
requestHeaderNames: new Set(DEFAULT_REQUEST_HEADERS),
|
|
209
|
+
responseHeaderNames: new Set(DEFAULT_RESPONSE_HEADERS),
|
|
210
|
+
isScoped,
|
|
211
|
+
requestHeaderCasing: new Map(CANONICAL_REQUEST_HEADERS),
|
|
212
|
+
responseHeaderCasing: new Map(CANONICAL_RESPONSE_HEADERS)
|
|
213
|
+
});
|
|
214
|
+
break;
|
|
215
|
+
|
|
216
|
+
case 'matchHeaders':
|
|
217
|
+
compiled.push({
|
|
218
|
+
urlRegex,
|
|
219
|
+
requestHeaderNames: new Set(
|
|
220
|
+
rule.headers.map(h => h.toLowerCase())
|
|
221
|
+
),
|
|
222
|
+
responseHeaderNames: new Set(
|
|
223
|
+
rule.headers.map(h => h.toLowerCase())
|
|
224
|
+
),
|
|
225
|
+
isScoped,
|
|
226
|
+
requestHeaderCasing: new Map(
|
|
227
|
+
rule.headers.map(
|
|
228
|
+
h => [h.toLowerCase(), h] as [string, string]
|
|
229
|
+
)
|
|
230
|
+
),
|
|
231
|
+
responseHeaderCasing: new Map(
|
|
232
|
+
rule.headers.map(
|
|
233
|
+
h => [h.toLowerCase(), h] as [string, string]
|
|
234
|
+
)
|
|
235
|
+
)
|
|
236
|
+
});
|
|
237
|
+
break;
|
|
238
|
+
|
|
239
|
+
case 'matchRequestHeaders':
|
|
240
|
+
compiled.push({
|
|
241
|
+
urlRegex,
|
|
242
|
+
requestHeaderNames: new Set(
|
|
243
|
+
rule.headers.map(h => h.toLowerCase())
|
|
244
|
+
),
|
|
245
|
+
responseHeaderNames: new Set(),
|
|
246
|
+
isScoped,
|
|
247
|
+
requestHeaderCasing: new Map(
|
|
248
|
+
rule.headers.map(
|
|
249
|
+
h => [h.toLowerCase(), h] as [string, string]
|
|
250
|
+
)
|
|
251
|
+
),
|
|
252
|
+
responseHeaderCasing: new Map()
|
|
253
|
+
});
|
|
254
|
+
break;
|
|
255
|
+
|
|
256
|
+
case 'matchResponseHeaders':
|
|
257
|
+
compiled.push({
|
|
258
|
+
urlRegex,
|
|
259
|
+
requestHeaderNames: new Set(),
|
|
260
|
+
responseHeaderNames: new Set(
|
|
261
|
+
rule.headers.map(h => h.toLowerCase())
|
|
262
|
+
),
|
|
263
|
+
isScoped,
|
|
264
|
+
requestHeaderCasing: new Map(),
|
|
265
|
+
responseHeaderCasing: new Map(
|
|
266
|
+
rule.headers.map(
|
|
267
|
+
h => [h.toLowerCase(), h] as [string, string]
|
|
268
|
+
)
|
|
269
|
+
)
|
|
270
|
+
});
|
|
271
|
+
break;
|
|
272
|
+
|
|
273
|
+
default:
|
|
274
|
+
// Unknown types are rejected by getRuleValidationError
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return compiled;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Converts a user-supplied header capture config into a runtime-efficient
|
|
284
|
+
* `CompiledHeaderCaptureConfig` (which is `CompiledHeaderCaptureRule[] | null`).
|
|
285
|
+
*
|
|
286
|
+
* Runs once at SDK initialization. Produces pre-built `RegExp` objects and `Set<string>`
|
|
287
|
+
* lookups so that per-request header matching is O(1) with no config traversal.
|
|
288
|
+
*
|
|
289
|
+
* Input: `'defaults' | HeaderCaptureRule[] | undefined`
|
|
290
|
+
* - `undefined` (omitted) = disabled, returns `null`
|
|
291
|
+
* - `'defaults'` = string shortcut, returns single-element array with default headers and catch-all regex
|
|
292
|
+
* - `HeaderCaptureRule[]` = composable array of rules, compiled into `CompiledHeaderCaptureRule[]`
|
|
293
|
+
* - `[]` (empty array) = logs WARN, returns `null`
|
|
294
|
+
* - Invalid value = logs WARN, returns `null`
|
|
295
|
+
*/
|
|
296
|
+
export const compileHeaderCaptureConfig = (
|
|
297
|
+
config: 'defaults' | HeaderCaptureRule[] | undefined
|
|
298
|
+
): CompiledHeaderCaptureConfig => {
|
|
299
|
+
if (config == null) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (config === 'defaults') {
|
|
304
|
+
return [
|
|
305
|
+
{
|
|
306
|
+
requestHeaderNames: new Set(DEFAULT_REQUEST_HEADERS),
|
|
307
|
+
responseHeaderNames: new Set(DEFAULT_RESPONSE_HEADERS),
|
|
308
|
+
urlRegex: /.*/,
|
|
309
|
+
isScoped: false,
|
|
310
|
+
requestHeaderCasing: new Map(CANONICAL_REQUEST_HEADERS),
|
|
311
|
+
responseHeaderCasing: new Map(CANONICAL_RESPONSE_HEADERS)
|
|
312
|
+
}
|
|
313
|
+
];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (Array.isArray(config)) {
|
|
317
|
+
if (config.length === 0) {
|
|
318
|
+
InternalLog.log(
|
|
319
|
+
'[DatadogRUM] headerCaptureRules is empty, no headers will be captured.',
|
|
320
|
+
SdkVerbosity.WARN
|
|
321
|
+
);
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const compiled = compileRules(config);
|
|
326
|
+
if (compiled.length === 0) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
return compiled;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
InternalLog.log(
|
|
333
|
+
`[DatadogRUM] headerCaptureRules: Unrecognized value "${JSON.stringify(
|
|
334
|
+
config
|
|
335
|
+
)}" — defaulting to disabled.`,
|
|
336
|
+
SdkVerbosity.WARN
|
|
337
|
+
);
|
|
338
|
+
return null;
|
|
339
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { InternalLog } from '../../../../InternalLog';
|
|
8
|
+
import { SdkVerbosity } from '../../../../config/types';
|
|
9
|
+
import { utf8ByteLength } from '../../../../utils/stringUtils';
|
|
10
|
+
|
|
11
|
+
const TAG = '[DatadogRUM][HeaderCapture]';
|
|
12
|
+
|
|
13
|
+
/** Maximum UTF-8 byte length for any single header value. */
|
|
14
|
+
|
|
15
|
+
export const MAX_HEADER_VALUE_BYTES = 128;
|
|
16
|
+
|
|
17
|
+
/** Maximum combined header count (request + response). */
|
|
18
|
+
export const MAX_HEADER_COUNT = 100;
|
|
19
|
+
|
|
20
|
+
/** Maximum total UTF-8 bytes across all header names and values. */
|
|
21
|
+
export const MAX_TOTAL_BYTES = 2048;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Truncates a string so its UTF-8 byte length does not exceed maxBytes.
|
|
25
|
+
* Single forward pass — O(n). Mirrors the surrogate-pair logic in utf8ByteLength.
|
|
26
|
+
*/
|
|
27
|
+
const truncateToBytes = (str: string, maxBytes: number): string => {
|
|
28
|
+
let bytes = 0;
|
|
29
|
+
for (let i = 0; i < str.length; i++) {
|
|
30
|
+
const code = str.charCodeAt(i);
|
|
31
|
+
let charBytes: number;
|
|
32
|
+
let advance = 1;
|
|
33
|
+
if (code < 0x80) {
|
|
34
|
+
charBytes = 1;
|
|
35
|
+
} else if (code < 0x800) {
|
|
36
|
+
charBytes = 2;
|
|
37
|
+
} else if (code >= 0xd800 && code <= 0xdbff) {
|
|
38
|
+
const next = i + 1 < str.length ? str.charCodeAt(i + 1) : 0;
|
|
39
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
40
|
+
charBytes = 4;
|
|
41
|
+
advance = 2;
|
|
42
|
+
} else {
|
|
43
|
+
charBytes = 3; // lone high surrogate
|
|
44
|
+
}
|
|
45
|
+
} else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
46
|
+
charBytes = 3; // lone low surrogate
|
|
47
|
+
} else {
|
|
48
|
+
charBytes = 3;
|
|
49
|
+
}
|
|
50
|
+
if (bytes + charBytes > maxBytes) {
|
|
51
|
+
return str.slice(0, i);
|
|
52
|
+
}
|
|
53
|
+
bytes += charBytes;
|
|
54
|
+
i += advance - 1; // -1 because the for-loop will also increment i
|
|
55
|
+
}
|
|
56
|
+
return str;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Converts a non-empty record to undefined-or-record.
|
|
61
|
+
* Locked decision: no empty objects -- undefined or absent, not `{}`.
|
|
62
|
+
*/
|
|
63
|
+
const toUndefinedIfEmpty = (
|
|
64
|
+
record: Record<string, string>
|
|
65
|
+
): Record<string, string> | undefined => {
|
|
66
|
+
return Object.keys(record).length > 0 ? record : undefined;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Enforces per-value truncation, header count cap, and total size budget
|
|
71
|
+
* on captured header records. All limits are in UTF-8 bytes.
|
|
72
|
+
*
|
|
73
|
+
* Processing order:
|
|
74
|
+
* 1. Short-circuit if both inputs undefined
|
|
75
|
+
* 2. Truncate each value to MAX_HEADER_VALUE_BYTES
|
|
76
|
+
* 3. Cap combined count to MAX_HEADER_COUNT (request priority)
|
|
77
|
+
* 4. Drop headers from end until total bytes <= MAX_TOTAL_BYTES
|
|
78
|
+
* 5. Return undefined (not {}) for empty records
|
|
79
|
+
*
|
|
80
|
+
* Pure function with no stateful side effects (emits DEBUG logs when limits are hit).
|
|
81
|
+
*/
|
|
82
|
+
export const enforceSizeLimits = (
|
|
83
|
+
requestHeaders: Record<string, string> | undefined,
|
|
84
|
+
responseHeaders: Record<string, string> | undefined
|
|
85
|
+
): {
|
|
86
|
+
requestHeaders: Record<string, string> | undefined;
|
|
87
|
+
responseHeaders: Record<string, string> | undefined;
|
|
88
|
+
} => {
|
|
89
|
+
// Step 1: Short-circuit
|
|
90
|
+
if (requestHeaders === undefined && responseHeaders === undefined) {
|
|
91
|
+
return { requestHeaders: undefined, responseHeaders: undefined };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Step 2: Truncate values to MAX_HEADER_VALUE_BYTES (UTF-8 bytes)
|
|
95
|
+
const reqEntries = requestHeaders
|
|
96
|
+
? Object.entries(requestHeaders).map(([name, value]): [
|
|
97
|
+
string,
|
|
98
|
+
string
|
|
99
|
+
] => {
|
|
100
|
+
const truncated = truncateToBytes(value, MAX_HEADER_VALUE_BYTES);
|
|
101
|
+
if (truncated.length < value.length) {
|
|
102
|
+
InternalLog.log(
|
|
103
|
+
`${TAG} Truncated request header "${name}" value from ${utf8ByteLength(
|
|
104
|
+
value
|
|
105
|
+
)} to ${MAX_HEADER_VALUE_BYTES} bytes`,
|
|
106
|
+
SdkVerbosity.DEBUG
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return [name, truncated];
|
|
110
|
+
})
|
|
111
|
+
: [];
|
|
112
|
+
|
|
113
|
+
const resEntries = responseHeaders
|
|
114
|
+
? Object.entries(responseHeaders).map(([name, value]): [
|
|
115
|
+
string,
|
|
116
|
+
string
|
|
117
|
+
] => {
|
|
118
|
+
const truncated = truncateToBytes(value, MAX_HEADER_VALUE_BYTES);
|
|
119
|
+
if (truncated.length < value.length) {
|
|
120
|
+
InternalLog.log(
|
|
121
|
+
`${TAG} Truncated response header "${name}" value from ${utf8ByteLength(
|
|
122
|
+
value
|
|
123
|
+
)} to ${MAX_HEADER_VALUE_BYTES} bytes`,
|
|
124
|
+
SdkVerbosity.DEBUG
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return [name, truncated];
|
|
128
|
+
})
|
|
129
|
+
: [];
|
|
130
|
+
|
|
131
|
+
// Step 3: Count cap -- request headers take priority
|
|
132
|
+
const totalCount = reqEntries.length + resEntries.length;
|
|
133
|
+
let cappedReqEntries = reqEntries;
|
|
134
|
+
let cappedResEntries = resEntries;
|
|
135
|
+
|
|
136
|
+
if (totalCount > MAX_HEADER_COUNT) {
|
|
137
|
+
const reqSlots = Math.min(reqEntries.length, MAX_HEADER_COUNT);
|
|
138
|
+
cappedReqEntries = reqEntries.slice(0, reqSlots);
|
|
139
|
+
const remainingSlots = MAX_HEADER_COUNT - cappedReqEntries.length;
|
|
140
|
+
cappedResEntries = resEntries.slice(0, remainingSlots);
|
|
141
|
+
InternalLog.log(
|
|
142
|
+
`${TAG} Header count cap hit (${totalCount} > ${MAX_HEADER_COUNT}): keeping ${cappedReqEntries.length} request + ${cappedResEntries.length} response headers`,
|
|
143
|
+
SdkVerbosity.DEBUG
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Step 4: Total byte budget -- drop from end (response first, then request)
|
|
148
|
+
let totalBytes = 0;
|
|
149
|
+
for (const [name, value] of cappedReqEntries) {
|
|
150
|
+
totalBytes += utf8ByteLength(name) + utf8ByteLength(value);
|
|
151
|
+
}
|
|
152
|
+
for (const [name, value] of cappedResEntries) {
|
|
153
|
+
totalBytes += utf8ByteLength(name) + utf8ByteLength(value);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (totalBytes > MAX_TOTAL_BYTES) {
|
|
157
|
+
InternalLog.log(
|
|
158
|
+
`${TAG} Total byte budget exceeded (${totalBytes} > ${MAX_TOTAL_BYTES}): dropping headers from end`,
|
|
159
|
+
SdkVerbosity.DEBUG
|
|
160
|
+
);
|
|
161
|
+
// Drop response headers from end first
|
|
162
|
+
while (cappedResEntries.length > 0 && totalBytes > MAX_TOTAL_BYTES) {
|
|
163
|
+
const entry = cappedResEntries.pop();
|
|
164
|
+
if (entry === undefined) {
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
InternalLog.log(
|
|
168
|
+
`${TAG} Dropped response header "${entry[0]}" to fit byte budget`,
|
|
169
|
+
SdkVerbosity.DEBUG
|
|
170
|
+
);
|
|
171
|
+
totalBytes -= utf8ByteLength(entry[0]) + utf8ByteLength(entry[1]);
|
|
172
|
+
}
|
|
173
|
+
// Then drop request headers from end
|
|
174
|
+
while (cappedReqEntries.length > 0 && totalBytes > MAX_TOTAL_BYTES) {
|
|
175
|
+
const entry = cappedReqEntries.pop();
|
|
176
|
+
if (entry === undefined) {
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
InternalLog.log(
|
|
180
|
+
`${TAG} Dropped request header "${entry[0]}" to fit byte budget`,
|
|
181
|
+
SdkVerbosity.DEBUG
|
|
182
|
+
);
|
|
183
|
+
totalBytes -= utf8ByteLength(entry[0]) + utf8ByteLength(entry[1]);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Step 5: Build result records
|
|
188
|
+
const reqResult: Record<string, string> = {};
|
|
189
|
+
for (const [name, value] of cappedReqEntries) {
|
|
190
|
+
reqResult[name] = value;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const resResult: Record<string, string> = {};
|
|
194
|
+
for (const [name, value] of cappedResEntries) {
|
|
195
|
+
resResult[name] = value;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
requestHeaders:
|
|
200
|
+
requestHeaders !== undefined
|
|
201
|
+
? toUndefinedIfEmpty(reqResult)
|
|
202
|
+
: undefined,
|
|
203
|
+
responseHeaders:
|
|
204
|
+
responseHeaders !== undefined
|
|
205
|
+
? toUndefinedIfEmpty(resResult)
|
|
206
|
+
: undefined
|
|
207
|
+
};
|
|
208
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { isSensitiveHeader } from './sensitiveHeaderBlocklist';
|
|
8
|
+
import { isTracingHeader } from './tracingHeaderExclusion';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Composed check: returns true if a header is allowed for capture.
|
|
12
|
+
* A header is allowed only if it is NOT sensitive AND NOT a tracing header.
|
|
13
|
+
*
|
|
14
|
+
* This is the single entry point for Phase 3 XHR integration to call for
|
|
15
|
+
* every header considered for capture.
|
|
16
|
+
*
|
|
17
|
+
* @param headerName - The header name to check (case-insensitive).
|
|
18
|
+
* @returns `true` if the header may be captured, `false` if blocked.
|
|
19
|
+
*/
|
|
20
|
+
export const isHeaderAllowed = (headerName: string): boolean => {
|
|
21
|
+
const lowered = headerName.toLowerCase();
|
|
22
|
+
if (isSensitiveHeader(lowered)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (isTracingHeader(lowered)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
};
|