@datadog/mobile-react-native 3.11.0 → 3.13.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.
Files changed (342) hide show
  1. package/DatadogSDKReactNative.podspec +357 -14
  2. package/README.md +5 -3
  3. package/android/build.gradle +23 -14
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +27 -2
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +27 -2
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +25 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +4 -0
  9. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +104 -0
  10. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +8 -0
  11. package/android/src/test/resources/input/complete-configuration.json +5 -0
  12. package/datadog-configuration.gradle +59 -18
  13. package/datadog-configuration.schema.json +140 -0
  14. package/ios/Sources/DdFlagsImplementation.swift +3 -0
  15. package/ios/Sources/DdSdkConfiguration.swift +11 -1
  16. package/ios/Sources/DdSdkNativeInitialization.swift +24 -2
  17. package/ios/Sources/RNDdSdkConfiguration.swift +14 -2
  18. package/ios/Sources/SdkVersion.swift +1 -1
  19. package/lib/commonjs/DdSdkReactNative.js +6 -1
  20. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  21. package/lib/commonjs/config/FileBasedConfiguration.js +4 -1
  22. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  23. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +3 -1
  24. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  25. package/lib/commonjs/config/features/RumConfiguration.js +8 -0
  26. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  27. package/lib/commonjs/config/features/RumConfigurationNative.js +4 -0
  28. package/lib/commonjs/config/types/TimeseriesConfiguration.js +25 -0
  29. package/lib/commonjs/config/types/TimeseriesConfiguration.js.map +1 -0
  30. package/lib/commonjs/config/types/index.js +7 -0
  31. package/lib/commonjs/config/types/index.js.map +1 -1
  32. package/lib/commonjs/flags/DdFlags.js +4 -2
  33. package/lib/commonjs/flags/DdFlags.js.map +1 -1
  34. package/lib/commonjs/flags/FlagsClient.js +4 -2
  35. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  36. package/lib/commonjs/index.js +7 -0
  37. package/lib/commonjs/index.js.map +1 -1
  38. package/lib/commonjs/internal.js +97 -0
  39. package/lib/commonjs/internal.js.map +1 -0
  40. package/lib/commonjs/logs/DdLogs.js +4 -2
  41. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  42. package/lib/commonjs/rum/DdRum.js +4 -2
  43. package/lib/commonjs/rum/DdRum.js.map +1 -1
  44. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
  45. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  47. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  48. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
  52. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  53. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
  54. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  55. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
  56. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  59. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
  64. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  65. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
  66. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  67. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  68. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  69. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  70. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  71. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  72. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  73. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
  74. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  75. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  76. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  77. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  78. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  79. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
  80. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  81. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  82. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  83. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  84. package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
  85. package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
  86. package/lib/commonjs/specs/NativeDdFlags.js +19 -3
  87. package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
  88. package/lib/commonjs/specs/NativeDdLogs.js +19 -3
  89. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
  90. package/lib/commonjs/specs/NativeDdRum.js +19 -3
  91. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  92. package/lib/commonjs/specs/NativeDdSdk.js +19 -3
  93. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
  94. package/lib/commonjs/specs/NativeDdTrace.js +19 -3
  95. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
  96. package/lib/commonjs/trace/DdTrace.js +4 -2
  97. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  98. package/lib/commonjs/utils/stringUtils.js +48 -0
  99. package/lib/commonjs/utils/stringUtils.js.map +1 -0
  100. package/lib/commonjs/version.js +1 -1
  101. package/lib/module/DdSdkReactNative.js +6 -1
  102. package/lib/module/DdSdkReactNative.js.map +1 -1
  103. package/lib/module/config/FileBasedConfiguration.js +4 -1
  104. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  105. package/lib/module/config/async/AutoInstrumentationConfiguration.js +3 -1
  106. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  107. package/lib/module/config/features/RumConfiguration.js +8 -0
  108. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  109. package/lib/module/config/features/RumConfigurationNative.js +1 -1
  110. package/lib/module/config/types/TimeseriesConfiguration.js +19 -0
  111. package/lib/module/config/types/TimeseriesConfiguration.js.map +1 -0
  112. package/lib/module/config/types/index.js +1 -0
  113. package/lib/module/config/types/index.js.map +1 -1
  114. package/lib/module/flags/DdFlags.js +4 -2
  115. package/lib/module/flags/DdFlags.js.map +1 -1
  116. package/lib/module/flags/FlagsClient.js +5 -2
  117. package/lib/module/flags/FlagsClient.js.map +1 -1
  118. package/lib/module/index.js +2 -1
  119. package/lib/module/index.js.map +1 -1
  120. package/lib/module/internal.js +27 -0
  121. package/lib/module/internal.js.map +1 -0
  122. package/lib/module/logs/DdLogs.js +4 -2
  123. package/lib/module/logs/DdLogs.js.map +1 -1
  124. package/lib/module/rum/DdRum.js +4 -2
  125. package/lib/module/rum/DdRum.js.map +1 -1
  126. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
  127. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  128. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  129. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  130. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
  131. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  132. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  133. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
  134. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  135. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
  136. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  137. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
  138. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  139. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
  140. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  141. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
  142. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  143. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
  144. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  145. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
  146. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  147. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
  148. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  149. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  150. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  151. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  152. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  153. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  154. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  155. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
  156. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  157. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  158. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  159. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  160. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  161. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
  162. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  163. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  164. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  165. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  166. package/lib/module/sdk/DdSdkInternal.js +27 -22
  167. package/lib/module/sdk/DdSdkInternal.js.map +1 -1
  168. package/lib/module/specs/NativeDdFlags.js +14 -2
  169. package/lib/module/specs/NativeDdFlags.js.map +1 -1
  170. package/lib/module/specs/NativeDdLogs.js +14 -2
  171. package/lib/module/specs/NativeDdLogs.js.map +1 -1
  172. package/lib/module/specs/NativeDdRum.js +14 -2
  173. package/lib/module/specs/NativeDdRum.js.map +1 -1
  174. package/lib/module/specs/NativeDdSdk.js +14 -2
  175. package/lib/module/specs/NativeDdSdk.js.map +1 -1
  176. package/lib/module/specs/NativeDdTrace.js +14 -2
  177. package/lib/module/specs/NativeDdTrace.js.map +1 -1
  178. package/lib/module/trace/DdTrace.js +4 -2
  179. package/lib/module/trace/DdTrace.js.map +1 -1
  180. package/lib/module/utils/stringUtils.js +42 -0
  181. package/lib/module/utils/stringUtils.js.map +1 -0
  182. package/lib/module/version.js +1 -1
  183. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  184. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  185. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +4 -1
  186. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  187. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +6 -0
  188. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  189. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts +2 -1
  190. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
  191. package/lib/typescript/config/features/RumConfiguration.d.ts +6 -1
  192. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  193. package/lib/typescript/config/features/RumConfiguration.type.d.ts +116 -1
  194. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  195. package/lib/typescript/config/features/RumConfigurationNative.d.ts +2 -0
  196. package/lib/typescript/config/features/RumConfigurationNative.d.ts.map +1 -1
  197. package/lib/typescript/config/types/TimeseriesConfiguration.d.ts +19 -0
  198. package/lib/typescript/config/types/TimeseriesConfiguration.d.ts.map +1 -0
  199. package/lib/typescript/config/types/index.d.ts +2 -0
  200. package/lib/typescript/config/types/index.d.ts.map +1 -1
  201. package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
  202. package/lib/typescript/flags/FlagsClient.d.ts +1 -1
  203. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  204. package/lib/typescript/index.d.ts +5 -2
  205. package/lib/typescript/index.d.ts.map +1 -1
  206. package/lib/typescript/internal.d.ts +26 -0
  207. package/lib/typescript/internal.d.ts.map +1 -0
  208. package/lib/typescript/logs/DdLogs.d.ts +1 -1
  209. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  210. package/lib/typescript/rum/DdRum.d.ts +1 -1
  211. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  212. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
  213. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
  214. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  215. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
  216. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
  217. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
  218. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
  219. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
  220. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
  221. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
  222. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
  223. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
  224. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
  225. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
  226. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
  227. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
  228. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
  229. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
  230. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
  231. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
  232. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
  233. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
  234. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
  235. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
  236. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  237. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
  238. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
  239. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  240. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
  241. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
  242. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
  243. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  244. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
  245. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  246. package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
  247. package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
  248. package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
  249. package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
  250. package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
  251. package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
  252. package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
  253. package/lib/typescript/specs/NativeDdRum.d.ts +7 -2
  254. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  255. package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
  256. package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
  257. package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
  258. package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
  259. package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
  260. package/lib/typescript/utils/stringUtils.d.ts +12 -0
  261. package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
  262. package/lib/typescript/version.d.ts +1 -1
  263. package/package.json +8 -3
  264. package/src/DdSdkReactNative.tsx +11 -1
  265. package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
  266. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +6 -0
  267. package/src/__tests__/internalEntry.test.ts +26 -0
  268. package/src/__tests__/mock.test.ts +1 -3
  269. package/src/__tests__/nativeSpecGetters.test.ts +102 -0
  270. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
  271. package/src/__tests__/wrapperImportSafety.test.ts +129 -0
  272. package/src/config/FileBasedConfiguration.ts +6 -1
  273. package/src/config/FileBasedConfiguration.type.ts +4 -0
  274. package/src/config/__tests__/FileBasedConfiguration.test.ts +73 -0
  275. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +14 -1
  276. package/src/config/async/AutoInstrumentationConfiguration.ts +9 -1
  277. package/src/config/async/PartialInitializationConfiguration.ts +2 -0
  278. package/src/config/features/RumConfiguration.ts +15 -0
  279. package/src/config/features/RumConfiguration.type.ts +128 -1
  280. package/src/config/features/RumConfigurationNative.ts +3 -0
  281. package/src/config/types/TimeseriesConfiguration.ts +26 -0
  282. package/src/config/types/index.ts +5 -0
  283. package/src/flags/DdFlags.ts +4 -3
  284. package/src/flags/FlagsClient.ts +4 -3
  285. package/src/index.tsx +15 -0
  286. package/src/internal.ts +32 -0
  287. package/src/logs/DdLogs.ts +4 -3
  288. package/src/rum/DdRum.ts +4 -3
  289. package/src/rum/__tests__/DdRum.test.ts +4 -4
  290. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
  291. package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
  292. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
  293. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
  294. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
  295. package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
  296. package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
  297. package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  298. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
  299. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
  300. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
  301. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
  302. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
  303. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
  304. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
  305. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
  306. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
  307. package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
  308. package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
  309. package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
  310. package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
  311. package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
  312. package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
  313. package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
  314. package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
  315. package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
  316. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +21 -2
  317. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +274 -0
  318. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
  319. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +34 -3
  320. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +624 -2
  321. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
  322. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +6 -1
  323. package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
  324. package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
  325. package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
  326. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
  327. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
  328. package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
  329. package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
  330. package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
  331. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +54 -1
  332. package/src/sdk/DdSdkInternal.ts +27 -24
  333. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
  334. package/src/specs/NativeDdFlags.ts +14 -2
  335. package/src/specs/NativeDdLogs.ts +14 -2
  336. package/src/specs/NativeDdRum.ts +14 -2
  337. package/src/specs/NativeDdSdk.ts +14 -2
  338. package/src/specs/NativeDdTrace.ts +14 -2
  339. package/src/trace/DdTrace.ts +4 -3
  340. package/src/utils/__tests__/stringUtils.test.ts +90 -0
  341. package/src/utils/stringUtils.ts +41 -0
  342. package/src/version.ts +1 -1
@@ -0,0 +1,183 @@
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 { NativeModules } from 'react-native';
8
+
9
+ import { BufferSingleton } from '../../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
10
+ import { XMLHttpRequestMock } from '../../__tests__/__utils__/XMLHttpRequestMock';
11
+ import { firstPartyHostsRegexMapBuilder } from '../../distributedTracing/firstPartyHosts';
12
+ import { XHRProxy } from '../../requestProxy/XHRProxy/XHRProxy';
13
+ import { ResourceReporter } from '../../requestProxy/common/ResourceReporter';
14
+ import {
15
+ DEFAULT_REQUEST_HEADERS,
16
+ DEFAULT_RESPONSE_HEADERS,
17
+ CANONICAL_REQUEST_HEADERS,
18
+ CANONICAL_RESPONSE_HEADERS
19
+ } from '../captureHeaders';
20
+ import * as enforceSizeLimitsModule from '../enforceSizeLimits';
21
+ import { MAX_HEADER_VALUE_BYTES } from '../enforceSizeLimits';
22
+ import type { CompiledHeaderCaptureConfig } from '../types';
23
+
24
+ jest.useFakeTimers();
25
+
26
+ const DdNativeRum = NativeModules.DdRum;
27
+
28
+ const flushPromises = () =>
29
+ new Promise(jest.requireActual('timers').setImmediate);
30
+
31
+ let xhrProxy: any;
32
+
33
+ beforeEach(() => {
34
+ DdNativeRum.startResource.mockClear();
35
+ DdNativeRum.stopResource.mockClear();
36
+ BufferSingleton.onInitialization();
37
+
38
+ xhrProxy = new XHRProxy({
39
+ xhrType: XMLHttpRequestMock,
40
+ resourceReporter: new ResourceReporter([])
41
+ } as {
42
+ xhrType: typeof XMLHttpRequest;
43
+ resourceReporter: ResourceReporter;
44
+ });
45
+
46
+ let now = Date.now();
47
+ jest.spyOn(Date, 'now').mockImplementation(() => {
48
+ now += 5;
49
+ return now;
50
+ });
51
+ });
52
+
53
+ afterEach(() => {
54
+ xhrProxy.onTrackingStop();
55
+ (Date.now as jest.MockedFunction<typeof Date.now>).mockClear();
56
+ });
57
+
58
+ describe('enforceSizeLimits integration', () => {
59
+ it('truncates oversized header values before they reach stopResource', async () => {
60
+ // GIVEN - a value longer than MAX_HEADER_VALUE_BYTES
61
+ const longValue = 'x'.repeat(256);
62
+ const method = 'GET';
63
+ const url = 'https://api.example.com/data';
64
+ const defaultsConfig: CompiledHeaderCaptureConfig = [
65
+ {
66
+ urlRegex: /.*/,
67
+ requestHeaderNames: new Set(DEFAULT_REQUEST_HEADERS),
68
+ responseHeaderNames: new Set(DEFAULT_RESPONSE_HEADERS),
69
+ isScoped: false,
70
+ requestHeaderCasing: new Map(CANONICAL_REQUEST_HEADERS),
71
+ responseHeaderCasing: new Map(CANONICAL_RESPONSE_HEADERS)
72
+ }
73
+ ];
74
+ xhrProxy.onTrackingStart({
75
+ tracingSamplingRate: 100,
76
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
77
+ headerCaptureConfig: defaultsConfig
78
+ });
79
+
80
+ // WHEN
81
+ const xhr = new XMLHttpRequestMock();
82
+ xhr.open(method, url);
83
+ xhr.setRequestHeader('Content-Type', longValue);
84
+ xhr.send();
85
+ xhr.notifyResponseArrived();
86
+ xhr.getAllResponseHeaders.mockReturnValue(
87
+ `content-type: ${longValue}\r\n`
88
+ );
89
+ xhr.complete(200, 'ok');
90
+ await flushPromises();
91
+
92
+ // THEN - values are truncated to MAX_HEADER_VALUE_BYTES
93
+ const stopContext = DdNativeRum.stopResource.mock.calls[0][4];
94
+ expect(stopContext['_dd.request_headers']['Content-Type'].length).toBe(
95
+ MAX_HEADER_VALUE_BYTES
96
+ );
97
+ expect(stopContext['_dd.response_headers']['Content-Type'].length).toBe(
98
+ MAX_HEADER_VALUE_BYTES
99
+ );
100
+ });
101
+
102
+ it('disabled config (null): enforceSizeLimits is never invoked', async () => {
103
+ // GIVEN
104
+ const spy = jest.spyOn(enforceSizeLimitsModule, 'enforceSizeLimits');
105
+
106
+ const method = 'GET';
107
+ const url = 'https://api.example.com/data';
108
+ const disabledConfig: CompiledHeaderCaptureConfig = null;
109
+ xhrProxy.onTrackingStart({
110
+ tracingSamplingRate: 100,
111
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
112
+ headerCaptureConfig: disabledConfig
113
+ });
114
+
115
+ // WHEN
116
+ const xhr = new XMLHttpRequestMock();
117
+ xhr.open(method, url);
118
+ xhr.setRequestHeader('Content-Type', 'application/json');
119
+ xhr.send();
120
+ xhr.notifyResponseArrived();
121
+ xhr.getAllResponseHeaders.mockReturnValue(
122
+ 'content-type: text/html\r\n'
123
+ );
124
+ xhr.complete(200, 'ok');
125
+ await flushPromises();
126
+
127
+ // THEN - enforceSizeLimits was NOT called (zero overhead)
128
+ expect(spy).not.toHaveBeenCalled();
129
+
130
+ // Also verify no headers in stopResource context
131
+ const stopContext = DdNativeRum.stopResource.mock.calls[0][4];
132
+ expect(stopContext['_dd.request_headers']).toBeUndefined();
133
+ expect(stopContext['_dd.response_headers']).toBeUndefined();
134
+
135
+ spy.mockRestore();
136
+ });
137
+
138
+ it('silent operation: no console warnings or errors during enforcement', async () => {
139
+ // GIVEN - oversized headers that will trigger truncation
140
+ const longValue = 'y'.repeat(256);
141
+ const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
142
+ const consoleErrorSpy = jest
143
+ .spyOn(console, 'error')
144
+ .mockImplementation();
145
+
146
+ const method = 'GET';
147
+ const url = 'https://api.example.com/data';
148
+ const defaultsConfig: CompiledHeaderCaptureConfig = [
149
+ {
150
+ urlRegex: /.*/,
151
+ requestHeaderNames: new Set(DEFAULT_REQUEST_HEADERS),
152
+ responseHeaderNames: new Set(DEFAULT_RESPONSE_HEADERS),
153
+ isScoped: false,
154
+ requestHeaderCasing: new Map(CANONICAL_REQUEST_HEADERS),
155
+ responseHeaderCasing: new Map(CANONICAL_RESPONSE_HEADERS)
156
+ }
157
+ ];
158
+ xhrProxy.onTrackingStart({
159
+ tracingSamplingRate: 100,
160
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
161
+ headerCaptureConfig: defaultsConfig
162
+ });
163
+
164
+ // WHEN
165
+ const xhr = new XMLHttpRequestMock();
166
+ xhr.open(method, url);
167
+ xhr.setRequestHeader('Content-Type', longValue);
168
+ xhr.send();
169
+ xhr.notifyResponseArrived();
170
+ xhr.getAllResponseHeaders.mockReturnValue(
171
+ `content-type: ${longValue}\r\n`
172
+ );
173
+ xhr.complete(200, 'ok');
174
+ await flushPromises();
175
+
176
+ // THEN - no console output during enforcement
177
+ expect(consoleWarnSpy).not.toHaveBeenCalled();
178
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
179
+
180
+ consoleWarnSpy.mockRestore();
181
+ consoleErrorSpy.mockRestore();
182
+ });
183
+ });
@@ -0,0 +1,337 @@
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 {
8
+ enforceSizeLimits,
9
+ MAX_HEADER_VALUE_BYTES,
10
+ MAX_HEADER_COUNT,
11
+ MAX_TOTAL_BYTES
12
+ } from '../enforceSizeLimits';
13
+
14
+ // Node's encoder is the reference: lone surrogates are encoded as U+FFFD (3 bytes)
15
+ const bytesOf = (value: string) => Buffer.byteLength(value, 'utf8');
16
+
17
+ const truncateValue = (value: string): string =>
18
+ enforceSizeLimits({ h: value }, undefined).requestHeaders?.h ?? '';
19
+
20
+ describe('enforceSizeLimits', () => {
21
+ describe('constants', () => {
22
+ it('exports MAX_HEADER_VALUE_BYTES as 128', () => {
23
+ expect(MAX_HEADER_VALUE_BYTES).toBe(128);
24
+ });
25
+
26
+ it('exports MAX_HEADER_COUNT as 100', () => {
27
+ expect(MAX_HEADER_COUNT).toBe(100);
28
+ });
29
+
30
+ it('exports MAX_TOTAL_BYTES as 2048', () => {
31
+ expect(MAX_TOTAL_BYTES).toBe(2048);
32
+ });
33
+ });
34
+
35
+ describe('undefined passthrough', () => {
36
+ it('returns both undefined when both inputs are undefined', () => {
37
+ const result = enforceSizeLimits(undefined, undefined);
38
+ expect(result.requestHeaders).toBeUndefined();
39
+ expect(result.responseHeaders).toBeUndefined();
40
+ });
41
+
42
+ it('passes through small request headers when response is undefined', () => {
43
+ const result = enforceSizeLimits({ a: 'b' }, undefined);
44
+ expect(result.requestHeaders).toEqual({ a: 'b' });
45
+ expect(result.responseHeaders).toBeUndefined();
46
+ });
47
+
48
+ it('passes through small response headers when request is undefined', () => {
49
+ const result = enforceSizeLimits(undefined, { a: 'b' });
50
+ expect(result.requestHeaders).toBeUndefined();
51
+ expect(result.responseHeaders).toEqual({ a: 'b' });
52
+ });
53
+ });
54
+
55
+ describe('value truncation', () => {
56
+ it('truncates header values longer than 128 bytes', () => {
57
+ const longValue = 'a'.repeat(200);
58
+ const result = enforceSizeLimits({ x: longValue }, undefined);
59
+ expect(result.requestHeaders?.['x']).toBe('a'.repeat(128));
60
+ expect(result.requestHeaders?.['x'].length).toBe(128);
61
+ });
62
+
63
+ it('does not truncate values exactly at 128 bytes', () => {
64
+ const exactValue = 'a'.repeat(128);
65
+ const result = enforceSizeLimits({ x: exactValue }, undefined);
66
+ expect(result.requestHeaders?.['x']).toBe(exactValue);
67
+ });
68
+
69
+ it('truncates response header values as well', () => {
70
+ const longValue = 'b'.repeat(200);
71
+ const result = enforceSizeLimits(undefined, {
72
+ y: longValue
73
+ });
74
+ expect(result.responseHeaders?.['y']).toBe('b'.repeat(128));
75
+ });
76
+ });
77
+
78
+ describe('UTF-8 value truncation', () => {
79
+ it.each([
80
+ ['2-byte characters exactly at the limit', 'é'.repeat(64), 64],
81
+ ['3-byte characters below the limit', '€'.repeat(42), 42],
82
+ [
83
+ 'an emoji ending exactly at the limit',
84
+ `${'a'.repeat(124)}😀`,
85
+ 126
86
+ ],
87
+ [
88
+ 'a lone high surrogate ending at the limit',
89
+ `${'a'.repeat(125)}\uD800`,
90
+ 126
91
+ ],
92
+ [
93
+ 'a lone low surrogate ending at the limit',
94
+ `${'a'.repeat(125)}\uDC00`,
95
+ 126
96
+ ]
97
+ ])('keeps %s intact', (_, value, expectedLength) => {
98
+ expect(bytesOf(value)).toBeLessThanOrEqual(MAX_HEADER_VALUE_BYTES);
99
+ expect(truncateValue(value)).toBe(value);
100
+ expect(value).toHaveLength(expectedLength);
101
+ });
102
+
103
+ it.each([
104
+ [
105
+ 'a 2-byte character crossing the limit',
106
+ `a${'é'.repeat(64)}`,
107
+ `a${'é'.repeat(63)}`
108
+ ],
109
+ [
110
+ 'a 3-byte character crossing the limit',
111
+ '€'.repeat(43),
112
+ '€'.repeat(42)
113
+ ],
114
+ [
115
+ 'an emoji crossing the limit',
116
+ `${'a'.repeat(126)}😀`,
117
+ 'a'.repeat(126)
118
+ ],
119
+ [
120
+ 'an emoji starting right after the limit',
121
+ `${'a'.repeat(128)}😀`,
122
+ 'a'.repeat(128)
123
+ ],
124
+ [
125
+ 'a lone high surrogate crossing the limit',
126
+ `${'a'.repeat(126)}\uD800`,
127
+ 'a'.repeat(126)
128
+ ],
129
+ [
130
+ 'a lone low surrogate crossing the limit',
131
+ `${'a'.repeat(126)}\uDC00`,
132
+ 'a'.repeat(126)
133
+ ]
134
+ ])('drops %s without splitting it', (_, value, expected) => {
135
+ const truncated = truncateValue(value);
136
+ expect(truncated).toBe(expected);
137
+ expect(bytesOf(truncated)).toBeLessThanOrEqual(
138
+ MAX_HEADER_VALUE_BYTES
139
+ );
140
+ });
141
+
142
+ it('never leaves a dangling high surrogate after truncation', () => {
143
+ for (let prefix = 120; prefix <= 128; prefix++) {
144
+ const truncated = truncateValue(
145
+ `${'a'.repeat(prefix)}${'😀'.repeat(4)}`
146
+ );
147
+ const lastCode = truncated.charCodeAt(truncated.length - 1);
148
+ expect(lastCode >= 0xd800 && lastCode <= 0xdbff).toBe(false);
149
+ expect(bytesOf(truncated)).toBeLessThanOrEqual(
150
+ MAX_HEADER_VALUE_BYTES
151
+ );
152
+ }
153
+ });
154
+ });
155
+
156
+ describe('header count cap', () => {
157
+ it('keeps all headers when combined count is at 100', () => {
158
+ const req: Record<string, string> = {};
159
+ const res: Record<string, string> = {};
160
+ for (let i = 0; i < 50; i++) {
161
+ req[`rq${i}`] = 'v';
162
+ res[`rs${i}`] = 'v';
163
+ }
164
+ const result = enforceSizeLimits(req, res);
165
+ expect(
166
+ Object.keys(result.requestHeaders ?? {}).length +
167
+ Object.keys(result.responseHeaders ?? {}).length
168
+ ).toBe(100);
169
+ });
170
+
171
+ it('caps total to 100 with request headers taking priority', () => {
172
+ const req: Record<string, string> = {};
173
+ const res: Record<string, string> = {};
174
+ for (let i = 0; i < 60; i++) {
175
+ req[`rq${i}`] = 'v';
176
+ res[`rs${i}`] = 'v';
177
+ }
178
+ const result = enforceSizeLimits(req, res);
179
+ expect(Object.keys(result.requestHeaders ?? {}).length).toBe(60);
180
+ expect(Object.keys(result.responseHeaders ?? {}).length).toBe(40);
181
+ });
182
+
183
+ it('caps request-only headers to 100', () => {
184
+ const req: Record<string, string> = {};
185
+ for (let i = 0; i < 110; i++) {
186
+ req[`h${i}`] = 'v';
187
+ }
188
+ const result = enforceSizeLimits(req, undefined);
189
+ expect(Object.keys(result.requestHeaders ?? {}).length).toBe(100);
190
+ expect(result.responseHeaders).toBeUndefined();
191
+ });
192
+
193
+ it('returns undefined for response when all its headers are dropped by count cap', () => {
194
+ const req: Record<string, string> = {};
195
+ for (let i = 0; i < 100; i++) {
196
+ req[`h${i}`] = 'v';
197
+ }
198
+ const res: Record<string, string> = { a: 'b' };
199
+ const result = enforceSizeLimits(req, res);
200
+ expect(Object.keys(result.requestHeaders ?? {}).length).toBe(100);
201
+ expect(result.responseHeaders).toBeUndefined();
202
+ });
203
+ });
204
+
205
+ describe('total size budget', () => {
206
+ it('drops response headers first when total exceeds 2048 bytes', () => {
207
+ // Each header: name(4) + value(100) = 104 bytes
208
+ // 20 headers = 2080 bytes > 2048
209
+ const req: Record<string, string> = {};
210
+ const res: Record<string, string> = {};
211
+ for (let i = 0; i < 10; i++) {
212
+ req[`rq${String(i).padStart(2, '0')}`] = 'x'.repeat(100);
213
+ res[`rs${String(i).padStart(2, '0')}`] = 'x'.repeat(100);
214
+ }
215
+ const result = enforceSizeLimits(req, res);
216
+ // Request headers should be preserved; response headers dropped from end
217
+ expect(Object.keys(result.requestHeaders ?? {}).length).toBe(10);
218
+ // Some response headers should be dropped
219
+ const totalBytes = computeTotalBytes(
220
+ result.requestHeaders,
221
+ result.responseHeaders
222
+ );
223
+ expect(totalBytes).toBeLessThanOrEqual(2048);
224
+ });
225
+
226
+ it('drops request headers from end if response fully dropped and still over budget', () => {
227
+ // 25 request headers each with name(3) + value(100) = 103 bytes
228
+ // 25 * 103 = 2575 > 2048
229
+ const req: Record<string, string> = {};
230
+ for (let i = 0; i < 25; i++) {
231
+ req[`h${String(i).padStart(1, '0')}`] = 'y'.repeat(100);
232
+ }
233
+ const result = enforceSizeLimits(req, undefined);
234
+ const totalBytes = computeTotalBytes(
235
+ result.requestHeaders,
236
+ result.responseHeaders
237
+ );
238
+ expect(totalBytes).toBeLessThanOrEqual(2048);
239
+ // Some request headers should be dropped
240
+ expect(
241
+ Object.keys(result.requestHeaders ?? {}).length
242
+ ).toBeLessThan(25);
243
+ });
244
+
245
+ it('returns undefined for response when all response headers dropped for budget', () => {
246
+ // 19 request headers: name(4) + value(100) = 104 each = 1976
247
+ // 1 response header: name(4) + value(100) = 104 -> total 2080 > 2048
248
+ const req: Record<string, string> = {};
249
+ for (let i = 0; i < 19; i++) {
250
+ req[`rq${String(i).padStart(2, '0')}`] = 'x'.repeat(100);
251
+ }
252
+ const res: Record<string, string> = {
253
+ rs00: 'x'.repeat(100)
254
+ };
255
+ const result = enforceSizeLimits(req, res);
256
+ expect(result.requestHeaders).toBeDefined();
257
+ expect(result.responseHeaders).toBeUndefined();
258
+ });
259
+
260
+ it('returns undefined for request when all headers dropped for budget', () => {
261
+ // Build a scenario where request has one giant-name header
262
+ // After truncation, still over budget -> request dropped entirely
263
+ const req: Record<string, string> = {};
264
+ // Create headers with long names that blow the budget
265
+ for (let i = 0; i < 30; i++) {
266
+ req['h'.repeat(70) + i] = 'v'.repeat(128);
267
+ }
268
+ const result = enforceSizeLimits(req, undefined);
269
+ const totalBytes = computeTotalBytes(
270
+ result.requestHeaders,
271
+ result.responseHeaders
272
+ );
273
+ expect(totalBytes).toBeLessThanOrEqual(2048);
274
+ });
275
+ });
276
+
277
+ describe('total size budget with multi-byte values', () => {
278
+ it('measures the budget in UTF-8 bytes, not UTF-16 code units', () => {
279
+ // 20 headers of 3 + 126 = 129 UTF-8 bytes (45 UTF-16 code units each):
280
+ // 900 code units in total, but 2580 bytes
281
+ const responseHeaders: Record<string, string> = {};
282
+ for (let i = 0; i < 20; i++) {
283
+ responseHeaders[`h${String(i).padStart(2, '0')}`] = '€'.repeat(
284
+ 42
285
+ );
286
+ }
287
+
288
+ const result = enforceSizeLimits(undefined, responseHeaders);
289
+ const kept = Object.entries(result.responseHeaders ?? {});
290
+ const keptBytes = kept.reduce(
291
+ (total, [name, value]) =>
292
+ total + bytesOf(name) + bytesOf(value),
293
+ 0
294
+ );
295
+
296
+ expect(kept).toHaveLength(15);
297
+ expect(keptBytes).toBe(15 * 129);
298
+ expect(keptBytes).toBeLessThanOrEqual(MAX_TOTAL_BYTES);
299
+ });
300
+ });
301
+
302
+ describe('combined processing order', () => {
303
+ it('truncates values before counting bytes for budget', () => {
304
+ // 10 headers with 500-char values -> truncated to 128 each
305
+ // After truncation: name(2) + value(128) = 130 each -> 1300 total < 2048
306
+ const req: Record<string, string> = {};
307
+ for (let i = 0; i < 10; i++) {
308
+ req[`h${i}`] = 'z'.repeat(500);
309
+ }
310
+ const result = enforceSizeLimits(req, undefined);
311
+ expect(Object.keys(result.requestHeaders ?? {}).length).toBe(10);
312
+ // All values truncated to 128
313
+ for (const value of Object.values(result.requestHeaders ?? {})) {
314
+ expect(value.length).toBeLessThanOrEqual(128);
315
+ }
316
+ });
317
+ });
318
+ });
319
+
320
+ /** Helper: compute total bytes for all headers */
321
+ function computeTotalBytes(
322
+ reqHeaders: Record<string, string> | undefined,
323
+ resHeaders: Record<string, string> | undefined
324
+ ): number {
325
+ let total = 0;
326
+ if (reqHeaders) {
327
+ for (const [name, value] of Object.entries(reqHeaders)) {
328
+ total += name.length + value.length;
329
+ }
330
+ }
331
+ if (resHeaders) {
332
+ for (const [name, value] of Object.entries(resHeaders)) {
333
+ total += name.length + value.length;
334
+ }
335
+ }
336
+ return total;
337
+ }
@@ -0,0 +1,35 @@
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 { isHeaderAllowed } from '../isHeaderAllowed';
8
+
9
+ describe('isHeaderAllowed', () => {
10
+ it('blocks sensitive headers', () => {
11
+ expect(isHeaderAllowed('authorization')).toBe(false);
12
+ });
13
+
14
+ it('blocks tracing headers', () => {
15
+ expect(isHeaderAllowed('x-datadog-trace-id')).toBe(false);
16
+ });
17
+
18
+ it('allows normal headers', () => {
19
+ expect(isHeaderAllowed('content-type')).toBe(true);
20
+ });
21
+
22
+ describe('case-insensitive', () => {
23
+ it('blocks Authorization (capitalized)', () => {
24
+ expect(isHeaderAllowed('Authorization')).toBe(false);
25
+ });
26
+
27
+ it('blocks X-B3-TraceId (mixed case tracing header)', () => {
28
+ expect(isHeaderAllowed('X-B3-TraceId')).toBe(false);
29
+ });
30
+ });
31
+
32
+ it('allows headers that pass both checks', () => {
33
+ expect(isHeaderAllowed('etag')).toBe(true);
34
+ });
35
+ });