dd-trace 5.135.0 → 5.137.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 +3 -0
- package/ci/cypress/support.js +2 -1
- package/ci/init.js +2 -22
- package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-setup.mjs +729 -724
- package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
- package/ext/exporters.js +0 -1
- package/index.d.ts +105 -5
- package/initialize.mjs +5 -2
- package/package.json +41 -36
- package/packages/datadog-esbuild/index.js +16 -70
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +6 -1
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +5 -2
- package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
- package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
- package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
- package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
- package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
- package/packages/datadog-instrumentations/src/graphql.js +20 -17
- package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +582 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +576 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
- package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +61 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +80 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +23 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
- package/packages/datadog-instrumentations/src/ioredis.js +101 -3
- package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
- package/packages/datadog-instrumentations/src/next.js +203 -26
- package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
- package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/router.js +35 -12
- package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
- package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
- package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
- package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -13
- package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-express/src/code_origin.js +2 -2
- package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +20 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +21 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +11 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
- package/packages/datadog-plugin-http/src/client.js +34 -10
- package/packages/datadog-plugin-http2/src/client.js +40 -14
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
- package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-postgres/src/index.js +118 -41
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
- package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
- package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
- package/packages/datadog-plugin-trpc/src/index.js +15 -0
- package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
- package/packages/datadog-plugin-trpc/src/request.js +81 -0
- package/packages/datadog-plugin-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +3 -2
- package/packages/datadog-plugin-ws/src/close.js +3 -5
- package/packages/datadog-plugin-ws/src/producer.js +1 -4
- package/packages/datadog-plugin-ws/src/receiver.js +3 -5
- package/packages/datadog-plugin-ws/src/server.js +44 -13
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-vite/index.js +537 -0
- package/packages/datadog-vite/src/log.js +5 -0
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/datadog-webpack/src/log.js +2 -29
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/index.js +1 -1
- package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
- package/packages/dd-trace/src/aiguard/sdk.js +8 -2
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +21 -1
- package/packages/dd-trace/src/appsec/channels.js +7 -0
- package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
- package/packages/dd-trace/src/appsec/graphql.js +89 -7
- package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
- package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
- package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
- package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
- package/packages/dd-trace/src/appsec/index.js +6 -0
- package/packages/dd-trace/src/appsec/lambda.js +17 -17
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
- package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
- package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
- package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
- package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
- package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
- package/packages/dd-trace/src/appsec/recommended.json +1358 -94
- package/packages/dd-trace/src/appsec/reporter.js +9 -0
- package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
- package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
- package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
- package/packages/dd-trace/src/appsec/waf/index.js +65 -6
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
- package/packages/dd-trace/src/before-exit.js +32 -0
- package/packages/dd-trace/src/bootstrap.js +5 -3
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
- package/packages/dd-trace/src/config/config-types.d.ts +3 -0
- package/packages/dd-trace/src/config/defaults.js +5 -0
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -4
- package/packages/dd-trace/src/config/index.js +63 -31
- package/packages/dd-trace/src/config/parsers.js +44 -0
- package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
- package/packages/dd-trace/src/config/remote_config.js +2 -1
- package/packages/dd-trace/src/config/supported-configurations.json +172 -10
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- package/packages/dd-trace/src/datastreams/pathway.js +113 -28
- package/packages/dd-trace/src/datastreams/processor.js +5 -4
- package/packages/dd-trace/src/debugger/config.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
- package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +2 -2
- package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +6 -2
- package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
- package/packages/dd-trace/src/exporter.js +0 -11
- package/packages/dd-trace/src/exporters/common/request.js +81 -48
- package/packages/dd-trace/src/exporters/common/retry.js +12 -7
- package/packages/dd-trace/src/exporters/common/url.js +1 -1
- package/packages/dd-trace/src/git_metadata.js +2 -1
- package/packages/dd-trace/src/id.js +1 -1
- package/packages/dd-trace/src/index.js +6 -3
- package/packages/dd-trace/src/lambda/facade.js +75 -0
- package/packages/dd-trace/src/lambda/handler.js +3 -41
- package/packages/dd-trace/src/lambda/index.js +38 -15
- package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
- package/packages/dd-trace/src/lambda/wrap.js +44 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/sdk.js +19 -0
- package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
- package/packages/dd-trace/src/llmobs/tagger.js +22 -0
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +6 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +7 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +55 -27
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
- package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
- package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
- package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
- package/packages/dd-trace/src/opentelemetry/span.js +2 -2
- package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
- package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +24 -0
- package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +143 -17
- package/packages/dd-trace/src/plugins/index.js +8 -0
- package/packages/dd-trace/src/plugins/plugin.js +4 -2
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +52 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +263 -82
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +80 -56
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
- package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
- package/packages/dd-trace/src/plugins/util/tags.js +6 -0
- package/packages/dd-trace/src/plugins/util/test.js +92 -40
- package/packages/dd-trace/src/plugins/util/url.js +18 -7
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +6 -6
- package/packages/dd-trace/src/plugins/util/web.js +65 -10
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiler.js +74 -12
- package/packages/dd-trace/src/profiling/profiler.js +30 -2
- package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
- package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
- package/packages/dd-trace/src/profiling/remote-config.js +354 -0
- package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/propagation-hash/index.js +7 -0
- package/packages/dd-trace/src/proxy.js +46 -54
- package/packages/dd-trace/src/span_processor.js +20 -0
- package/packages/dd-trace/src/startup-log.js +8 -6
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +2 -1
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
- package/vendor/dist/@datadog/flagging-core/index.js +1 -0
- package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
- package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
- package/vendor/dist/@datadog/source-map/LICENSE +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +220 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
- package/vendor/dist/escape-string-regexp/LICENSE +13 -0
- package/vendor/dist/esquery/LICENSE +2 -0
- package/vendor/dist/https-proxy-agent/LICENSE +80 -1
- package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
- package/vendor/dist/jest-docblock/LICENSE +16 -0
- package/vendor/dist/jsonpath-plus/LICENSE +13 -0
- package/vendor/dist/limiter/LICENSE +2 -0
- package/vendor/dist/lodash.sortby/LICENSE +2 -0
- package/vendor/dist/lru-cache/LICENSE +13 -0
- package/vendor/dist/meriyah/LICENSE +13 -0
- package/vendor/dist/module-details-from-path/LICENSE +2 -0
- package/vendor/dist/mutexify/promise/LICENSE +28 -0
- package/vendor/dist/pprof-format/LICENSE +13 -0
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/LICENSE +219 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
- package/vendor/dist/proxy-from-env/LICENSE +13 -0
- package/vendor/dist/retry/LICENSE +2 -0
- package/vendor/dist/rfdc/LICENSE +2 -0
- package/vendor/dist/semifies/LICENSE +3 -1
- package/vendor/dist/shell-quote/LICENSE +3 -1
- package/vendor/dist/source-map/LICENSE +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +1 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
- package/vendor/dist/ttl-set/LICENSE +28 -0
- package/vite.d.ts +7 -0
- package/vite.js +3 -0
- package/ci/diagnose.js +0 -2215
- package/ci/runbook.md +0 -299
- package/ci/test-optimization-validation/approval-artifacts.js +0 -175
- package/ci/test-optimization-validation/approval.js +0 -386
- package/ci/test-optimization-validation/artifact-id.js +0 -18
- package/ci/test-optimization-validation/blocker-category.js +0 -24
- package/ci/test-optimization-validation/bounded-json.js +0 -120
- package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
- package/ci/test-optimization-validation/ci-discovery.js +0 -192
- package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
- package/ci/test-optimization-validation/ci-remediation.js +0 -283
- package/ci/test-optimization-validation/cli.js +0 -954
- package/ci/test-optimization-validation/command-blocker.js +0 -377
- package/ci/test-optimization-validation/command-output-policy.js +0 -188
- package/ci/test-optimization-validation/command-runner.js +0 -649
- package/ci/test-optimization-validation/environment.js +0 -88
- package/ci/test-optimization-validation/executable-approval.js +0 -47
- package/ci/test-optimization-validation/executable.js +0 -244
- package/ci/test-optimization-validation/execution-lock.js +0 -70
- package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
- package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
- package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
- package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
- package/ci/test-optimization-validation/generated-file-policy.js +0 -63
- package/ci/test-optimization-validation/generated-files.js +0 -425
- package/ci/test-optimization-validation/generated-test-contract.js +0 -284
- package/ci/test-optimization-validation/generated-verifier.js +0 -235
- package/ci/test-optimization-validation/literal-environment.js +0 -56
- package/ci/test-optimization-validation/literal-glob.js +0 -52
- package/ci/test-optimization-validation/manifest-loader.js +0 -116
- package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
- package/ci/test-optimization-validation/manifest-schema.js +0 -695
- package/ci/test-optimization-validation/offline-fixtures.js +0 -335
- package/ci/test-optimization-validation/offline-output.js +0 -406
- package/ci/test-optimization-validation/package-check.js +0 -97
- package/ci/test-optimization-validation/payload-normalizer.js +0 -72
- package/ci/test-optimization-validation/plan-writer.js +0 -541
- package/ci/test-optimization-validation/preflight-runner.js +0 -186
- package/ci/test-optimization-validation/project-build-artifact.js +0 -31
- package/ci/test-optimization-validation/redaction.js +0 -319
- package/ci/test-optimization-validation/report-writer.js +0 -666
- package/ci/test-optimization-validation/result-semantics.js +0 -103
- package/ci/test-optimization-validation/runner-command.js +0 -264
- package/ci/test-optimization-validation/runner-contract.js +0 -695
- package/ci/test-optimization-validation/safe-files.js +0 -202
- package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
- package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
- package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
- package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
- package/ci/test-optimization-validation/source-text.js +0 -84
- package/ci/test-optimization-validation/static-diagnosis.js +0 -166
- package/ci/test-optimization-validation/test-output.js +0 -120
- package/ci/test-optimization-validation/validation-blocker.js +0 -21
- package/ci/validate-test-optimization.js +0 -3
- package/packages/datadog-esbuild/src/resolver.js +0 -284
- package/packages/datadog-esbuild/src/utils.js +0 -318
- package/packages/datadog-plugin-cypress/src/support.js +0 -1348
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
|
@@ -18,6 +18,7 @@ const clone = createRfdc({ proto: false, circles: false })
|
|
|
18
18
|
const { USER_ID, USER_SESSION_ID } = require('../appsec/addresses')
|
|
19
19
|
const { getActiveRequest } = require('../appsec/store')
|
|
20
20
|
const { ERROR_MESSAGE, ERROR_STACK, ERROR_TYPE, PROCESS_ID, SAMPLING_PRIORITY_KEY } = require('../constants')
|
|
21
|
+
const { MAX_META_KEY_LENGTH, MAX_META_VALUE_LENGTH } = require('../encode/tags-processors')
|
|
21
22
|
const log = require('../log')
|
|
22
23
|
const { keepTrace } = require('../priority_sampler')
|
|
23
24
|
const { extractIp } = require('../plugins/util/ip_extractor')
|
|
@@ -82,6 +83,8 @@ const ALLOW = 'ALLOW'
|
|
|
82
83
|
* @property {{ source: string, integration: string }} telemetryTags
|
|
83
84
|
*/
|
|
84
85
|
|
|
86
|
+
/** @typedef {{ [key: string]: string | number | boolean }} CustomTags */
|
|
87
|
+
|
|
85
88
|
/**
|
|
86
89
|
* Returns whether a value is a non-array object.
|
|
87
90
|
*
|
|
@@ -124,6 +127,62 @@ function normalizeExtraEntries (field, entries) {
|
|
|
124
127
|
return normalized.length === 0 ? NO_EXTRA_ENTRIES : normalized
|
|
125
128
|
}
|
|
126
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Returns whether a custom tag entry can be set on the AI Guard span.
|
|
132
|
+
*
|
|
133
|
+
* Only primitive values are accepted because the span flattens nested objects into dotted keys,
|
|
134
|
+
* which could otherwise smuggle reserved ai_guard.* keys in through a non-reserved parent key.
|
|
135
|
+
* Entries above the agent meta limits are dropped rather than truncated. The limits are checked in
|
|
136
|
+
* characters (UTF-16 code units), so the agent may still truncate values with multi-byte characters.
|
|
137
|
+
* A non-string service.name is dropped because the span formatter calls string methods on it when
|
|
138
|
+
* the trace is exported, after this function can catch the error.
|
|
139
|
+
*
|
|
140
|
+
* @param {string} key
|
|
141
|
+
* @param {unknown} value
|
|
142
|
+
*/
|
|
143
|
+
function isValidCustomTag (key, value) {
|
|
144
|
+
if (
|
|
145
|
+
key.length === 0 ||
|
|
146
|
+
key.length > MAX_META_KEY_LENGTH ||
|
|
147
|
+
key === TAGS.RESERVED_TAG_KEY ||
|
|
148
|
+
key.startsWith(TAGS.RESERVED_TAG_PREFIX)
|
|
149
|
+
) {
|
|
150
|
+
return false
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (typeof value === 'string') {
|
|
154
|
+
return value.length <= MAX_META_VALUE_LENGTH
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (key === SERVICE_NAME) return false
|
|
158
|
+
|
|
159
|
+
return typeof value === 'boolean' || Number.isFinite(value)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Sets caller-provided tags on the AI Guard span, dropping invalid or reserved entries.
|
|
164
|
+
*
|
|
165
|
+
* Must run after the service entry tags are copied: when the AI Guard span is the trace root, a
|
|
166
|
+
* custom usr.id or http.client_ip would otherwise be copied into the reserved ai_guard.* keys.
|
|
167
|
+
* Must also run before the verdict tags set in finish(): some of them are only set conditionally,
|
|
168
|
+
* and filtering reserved keys here is what keeps a caller value from misreporting the verdict.
|
|
169
|
+
*
|
|
170
|
+
* @param {Span} span
|
|
171
|
+
* @param {unknown} tags
|
|
172
|
+
*/
|
|
173
|
+
function setCustomTags (span, tags) {
|
|
174
|
+
if (!isRecord(tags)) return
|
|
175
|
+
|
|
176
|
+
for (const key of Object.keys(tags)) {
|
|
177
|
+
const value = tags[key]
|
|
178
|
+
if (isValidCustomTag(key, value)) {
|
|
179
|
+
span.setTag(key, value)
|
|
180
|
+
} else {
|
|
181
|
+
log.debug('AIGuard: dropping invalid custom tag %s', key)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
127
186
|
/**
|
|
128
187
|
* Parses the backend evaluation response into the tracer's internal contract.
|
|
129
188
|
*
|
|
@@ -309,7 +368,7 @@ class EvaluationReporter {
|
|
|
309
368
|
*
|
|
310
369
|
* @param {Span} span
|
|
311
370
|
* @param {Message[]} messages
|
|
312
|
-
* @param {{ source: string, integration: string }} options
|
|
371
|
+
* @param {{ source: string, integration: string, tags?: CustomTags }} options
|
|
313
372
|
* @returns {EvaluationReport}
|
|
314
373
|
*/
|
|
315
374
|
start (span, messages, options) {
|
|
@@ -339,6 +398,8 @@ class EvaluationReporter {
|
|
|
339
398
|
rootSpan.setTag(TAGS.EVENT_TAG_KEY, 'true')
|
|
340
399
|
}
|
|
341
400
|
|
|
401
|
+
if (options.tags !== undefined) setCustomTags(span, options.tags)
|
|
402
|
+
|
|
342
403
|
return {
|
|
343
404
|
span,
|
|
344
405
|
messages: evaluatedMessages,
|
|
@@ -21,7 +21,7 @@ function enable (tracer, config) {
|
|
|
21
21
|
const analyzeStreamResponses = config.aiguard.DD_AI_GUARD_ANALYZE_STREAM_RESPONSES_ENABLED
|
|
22
22
|
|
|
23
23
|
incomingHttpRequestStart.subscribe(onIncomingHttpRequestStart)
|
|
24
|
-
integrations.enable(aiguard, block, analyzeStreamResponses)
|
|
24
|
+
integrations.enable(aiguard, block, analyzeStreamResponses, config.aiguard.DD_AI_GUARD_DISABLED_INTEGRATIONS)
|
|
25
25
|
|
|
26
26
|
isEnabled = true
|
|
27
27
|
} catch (err) {
|
|
@@ -7,18 +7,19 @@ const vercelAi = require('./vercel-ai')
|
|
|
7
7
|
let isEnabled = false
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Enables
|
|
10
|
+
* Enables AI Guard provider integrations except those explicitly disabled.
|
|
11
11
|
*
|
|
12
12
|
* @param {object} aiguard
|
|
13
13
|
* @param {boolean} block
|
|
14
14
|
* @param {boolean} analyzeStreamResponses
|
|
15
|
+
* @param {string[]} [disabledIntegrations]
|
|
15
16
|
*/
|
|
16
|
-
function enable (aiguard, block, analyzeStreamResponses) {
|
|
17
|
+
function enable (aiguard, block, analyzeStreamResponses, disabledIntegrations = []) {
|
|
17
18
|
if (isEnabled) return
|
|
18
19
|
|
|
19
|
-
anthropic.enable(aiguard, block, analyzeStreamResponses)
|
|
20
|
-
openai.enable(aiguard, block, analyzeStreamResponses)
|
|
21
|
-
vercelAi.enable(aiguard, block, analyzeStreamResponses)
|
|
20
|
+
if (!disabledIntegrations.includes('anthropic')) anthropic.enable(aiguard, block, analyzeStreamResponses)
|
|
21
|
+
if (!disabledIntegrations.includes('openai')) openai.enable(aiguard, block, analyzeStreamResponses)
|
|
22
|
+
if (!disabledIntegrations.includes('ai')) vercelAi.enable(aiguard, block, analyzeStreamResponses)
|
|
22
23
|
|
|
23
24
|
isEnabled = true
|
|
24
25
|
}
|
|
@@ -28,12 +28,18 @@ class AIGuard extends NoopAIGuard {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
evaluate (messages, opts) {
|
|
31
|
-
const {
|
|
31
|
+
const {
|
|
32
|
+
block = true,
|
|
33
|
+
source = TAGS.SOURCE_SDK,
|
|
34
|
+
integration = TAGS.INTEGRATION_NONE,
|
|
35
|
+
childOf,
|
|
36
|
+
tags: customTags,
|
|
37
|
+
} = opts ?? {}
|
|
32
38
|
// Only pass `childOf` when truthy so `tracer.trace`'s default (`scope().active()`)
|
|
33
39
|
// still applies for SDK callers that don't supply an explicit parent.
|
|
34
40
|
const traceOpts = childOf ? { childOf } : {}
|
|
35
41
|
return this.#tracer.trace(TAGS.RESOURCE, traceOpts, async (span) => {
|
|
36
|
-
const report = this.#reporter.start(span, messages, { source, integration })
|
|
42
|
+
const report = this.#reporter.start(span, messages, { source, integration, tags: customTags })
|
|
37
43
|
let evaluation
|
|
38
44
|
try {
|
|
39
45
|
evaluation = await this.#client.evaluate(report.messages, this.#meta)
|
|
@@ -10,6 +10,8 @@ module.exports = {
|
|
|
10
10
|
REDACTED_TAG_KEY: 'ai_guard.redacted',
|
|
11
11
|
EVENT_TAG_KEY: 'ai_guard.event',
|
|
12
12
|
META_STRUCT_KEY: 'ai_guard',
|
|
13
|
+
RESERVED_TAG_KEY: 'ai_guard',
|
|
14
|
+
RESERVED_TAG_PREFIX: 'ai_guard.',
|
|
13
15
|
|
|
14
16
|
HTTP_USERAGENT_TAG_KEY: 'ai_guard.http.useragent',
|
|
15
17
|
HTTP_CLIENT_IP_TAG_KEY: 'ai_guard.http.client_ip',
|
|
@@ -40,6 +40,14 @@ const responseBlockedSet = new WeakSet()
|
|
|
40
40
|
|
|
41
41
|
const blockDelegations = new WeakMap()
|
|
42
42
|
|
|
43
|
+
// Abort reason for instrumentations that must reject an operation the application awaits.
|
|
44
|
+
class BlockedRequestError extends Error {
|
|
45
|
+
constructor () {
|
|
46
|
+
super('Request blocked by Datadog App and API Protection')
|
|
47
|
+
this.name = 'BlockedRequestError'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
43
51
|
const specificBlockingTypes = {
|
|
44
52
|
GRAPHQL: 'graphqlJson',
|
|
45
53
|
}
|
|
@@ -128,6 +136,14 @@ function block (req, res, rootSpan, abortController, actionParameters = defaultB
|
|
|
128
136
|
throw new Error('Headers have already been sent')
|
|
129
137
|
}
|
|
130
138
|
|
|
139
|
+
// A destroyed response accepts the writes without sending anything to the client.
|
|
140
|
+
if (res.destroyed) {
|
|
141
|
+
log.warn('[ASM] Cannot send blocking response when the response has been destroyed')
|
|
142
|
+
abortController?.abort(new BlockedRequestError())
|
|
143
|
+
|
|
144
|
+
throw new Error('Response has been destroyed')
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
const { body, headers, statusCode } = getBlockingData(req, null, actionParameters)
|
|
132
148
|
|
|
133
149
|
for (const headerName of res.getHeaderNames()) {
|
|
@@ -142,7 +158,11 @@ function block (req, res, rootSpan, abortController, actionParameters = defaultB
|
|
|
142
158
|
rootSpan.setTag('appsec.blocked', 'true')
|
|
143
159
|
|
|
144
160
|
responseBlockedSet.add(res)
|
|
145
|
-
|
|
161
|
+
|
|
162
|
+
// The blocking response is final, but frameworks may keep running and rewrite the status (Next.js restores it).
|
|
163
|
+
Object.defineProperty(res, 'statusCode', { configurable: true, enumerable: true, get: () => statusCode, set () {} })
|
|
164
|
+
|
|
165
|
+
abortController?.abort(new BlockedRequestError())
|
|
146
166
|
|
|
147
167
|
return true
|
|
148
168
|
} catch (err) {
|
|
@@ -20,8 +20,11 @@ module.exports = {
|
|
|
20
20
|
fastifyPathParams: dc.channel('datadog:fastify:path-params:finish'),
|
|
21
21
|
fastifyQueryParams: dc.channel('datadog:fastify:query-params:finish'),
|
|
22
22
|
fastifyResponseChannel: dc.channel('datadog:fastify:response:finish'),
|
|
23
|
+
fetchRequestStart: dc.channel('tracing:apm:fetch:request:start'),
|
|
23
24
|
fsOperationStart: dc.channel('apm:fs:operation:start'),
|
|
24
25
|
graphqlMiddlewareChannel: dc.tracingChannel('datadog:apollo:middleware'),
|
|
26
|
+
httpClientRequestFinish: dc.channel('apm:http:client:request:finish'),
|
|
27
|
+
httpClientRequestError: dc.channel('apm:http:client:request:error'),
|
|
25
28
|
httpClientRequestStart: dc.channel('apm:http:client:request:start'),
|
|
26
29
|
httpClientResponseStart: dc.channel('apm:http:client:response:start'),
|
|
27
30
|
httpClientResponseFinish: dc.channel('apm:http:client:response:finish'),
|
|
@@ -34,6 +37,10 @@ module.exports = {
|
|
|
34
37
|
mysql2OuterQueryStart: dc.channel('datadog:mysql2:outerquery:start'),
|
|
35
38
|
nextBodyParsed: dc.channel('apm:next:body-parsed'),
|
|
36
39
|
nextQueryParsed: dc.channel('apm:next:query-parsed'),
|
|
40
|
+
nextRequestStart: dc.channel('apm:next:request:start'),
|
|
41
|
+
nextResponseBody: dc.channel('tracing:orchestrion:next:responseBody:start'),
|
|
42
|
+
nextJsonResponse: dc.channel('apm:next:response:json'),
|
|
43
|
+
nextAppRouteResponse: dc.channel('tracing:orchestrion:next:appRouteResponse:asyncEnd'),
|
|
37
44
|
passportUser: dc.channel('datadog:passport:deserializeUser:finish'),
|
|
38
45
|
passportVerify: dc.channel('datadog:passport:verify:finish'),
|
|
39
46
|
pgPoolQueryStart: dc.channel('datadog:pg:pool:query:start'),
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
// Headers is only used for requests of the global fetch, which comes with it.
|
|
4
|
+
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['Headers'] }] */
|
|
5
|
+
|
|
3
6
|
const web = require('../plugins/util/web')
|
|
4
7
|
const log = require('../log')
|
|
5
8
|
const { isEmpty } = require('../util')
|
|
@@ -27,6 +30,19 @@ const RESPONSE_BODY_IGNORED_TAG_CONTENT_LENGTH_MISSING =
|
|
|
27
30
|
const RESPONSE_BODY_IGNORED_TAG_CONTENT_LENGTH_TOO_BIG =
|
|
28
31
|
'_dd.appsec.downstream_request.response_body_ignored.content_length_too_big'
|
|
29
32
|
|
|
33
|
+
const HTTP_TOKEN_PATTERN = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/
|
|
34
|
+
const FORBIDDEN_FETCH_METHODS = new Set(['connect', 'trace', 'track'])
|
|
35
|
+
const ARRAY_ITERATOR = Array.prototype[Symbol.iterator]
|
|
36
|
+
const NORMALIZED_FETCH_METHODS = new Map([
|
|
37
|
+
['delete', 'DELETE'],
|
|
38
|
+
['get', 'GET'],
|
|
39
|
+
['head', 'HEAD'],
|
|
40
|
+
['options', 'OPTIONS'],
|
|
41
|
+
['post', 'POST'],
|
|
42
|
+
['put', 'PUT'],
|
|
43
|
+
['query', 'QUERY'],
|
|
44
|
+
])
|
|
45
|
+
|
|
30
46
|
let config
|
|
31
47
|
let samplingRate
|
|
32
48
|
let globalRequestCounter
|
|
@@ -211,6 +227,94 @@ function extractRequestData (ctx) {
|
|
|
211
227
|
return addresses
|
|
212
228
|
}
|
|
213
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Extracts request data from an outgoing fetch request for WAF analysis.
|
|
232
|
+
* @param {Request} request outgoing fetch request.
|
|
233
|
+
* @param {import('undici-types').RequestInit} [init] options that fetch applies over `request`.
|
|
234
|
+
* @returns {object} a map of addresses and request data.
|
|
235
|
+
*/
|
|
236
|
+
function extractFetchRequestData (request, init) {
|
|
237
|
+
/** @type {Record<string, unknown>} */
|
|
238
|
+
const addresses = {}
|
|
239
|
+
|
|
240
|
+
// An override that can't be read as plain data is left out rather than reported with the value it replaces.
|
|
241
|
+
const method = init?.method === undefined ? request.method : getFetchMethod(init.method)
|
|
242
|
+
if (method !== undefined) {
|
|
243
|
+
addresses[HTTP_OUTGOING_METHOD] = method
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Header names of a fetch request are already lowercase.
|
|
247
|
+
const headers = init?.headers === undefined ? Object.fromEntries(request.headers) : getFetchHeaders(init.headers)
|
|
248
|
+
if (headers !== undefined && !isEmpty(headers)) {
|
|
249
|
+
addresses[HTTP_OUTGOING_HEADERS] = headers
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return addresses
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Returns the method that fetch sends for a method option, or undefined when fetch would reject it or would have to
|
|
257
|
+
* convert it to a string.
|
|
258
|
+
* @param {unknown} method method option of a fetch call.
|
|
259
|
+
* @returns {string | undefined}
|
|
260
|
+
*/
|
|
261
|
+
function getFetchMethod (method) {
|
|
262
|
+
if (typeof method !== 'string' || !HTTP_TOKEN_PATTERN.test(method)) return
|
|
263
|
+
|
|
264
|
+
const lowercaseMethod = method.toLowerCase()
|
|
265
|
+
if (FORBIDDEN_FETCH_METHODS.has(lowercaseMethod)) return
|
|
266
|
+
|
|
267
|
+
return NORMALIZED_FETCH_METHODS.get(lowercaseMethod) ?? method
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Returns the headers that fetch sends for a headers option, or undefined when the option is not plain data. Iterables
|
|
272
|
+
* other than plain arrays and Headers objects are left out: reading them could consume the values that fetch sends.
|
|
273
|
+
* @param {unknown} headers headers option of a fetch call.
|
|
274
|
+
* @returns {Record<string, string> | undefined}
|
|
275
|
+
*/
|
|
276
|
+
function getFetchHeaders (headers) {
|
|
277
|
+
if (typeof headers !== 'object' || headers === null) return
|
|
278
|
+
|
|
279
|
+
try {
|
|
280
|
+
const iterator = headers[Symbol.iterator]
|
|
281
|
+
let entries
|
|
282
|
+
if (iterator == null) {
|
|
283
|
+
entries = Object.entries(headers)
|
|
284
|
+
if (!entries.every(([, value]) => isFetchHeaderPrimitive(value))) return
|
|
285
|
+
} else if (iterator === ARRAY_ITERATOR && Array.isArray(headers)) {
|
|
286
|
+
if (!headers.every(isFetchHeaderEntry)) return
|
|
287
|
+
entries = headers
|
|
288
|
+
} else if (headers instanceof Headers && iterator === Headers.prototype[Symbol.iterator]) {
|
|
289
|
+
return Object.fromEntries(headers)
|
|
290
|
+
} else {
|
|
291
|
+
return
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Headers applies the normalization of fetch, and rejects the names and values that fetch rejects.
|
|
295
|
+
return Object.fromEntries(new Headers(entries))
|
|
296
|
+
} catch {}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @param {unknown} entry entry of a headers option given as an array.
|
|
301
|
+
*/
|
|
302
|
+
function isFetchHeaderEntry (entry) {
|
|
303
|
+
return Array.isArray(entry) &&
|
|
304
|
+
entry[Symbol.iterator] === ARRAY_ITERATOR &&
|
|
305
|
+
entry.length === 2 &&
|
|
306
|
+
isFetchHeaderPrimitive(entry[0]) &&
|
|
307
|
+
isFetchHeaderPrimitive(entry[1])
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Tells whether fetch converts a header name or value to a string without calling code of the application.
|
|
312
|
+
* @param {unknown} value header name or value of a headers option.
|
|
313
|
+
*/
|
|
314
|
+
function isFetchHeaderPrimitive (value) {
|
|
315
|
+
return value === null || (typeof value !== 'object' && typeof value !== 'function' && typeof value !== 'symbol')
|
|
316
|
+
}
|
|
317
|
+
|
|
214
318
|
/**
|
|
215
319
|
* Extracts response data for WAF analysis.
|
|
216
320
|
* @param {import('http').IncomingMessage} res downstream response object.
|
|
@@ -341,5 +445,6 @@ module.exports = {
|
|
|
341
445
|
incrementDownstreamAnalysisCount,
|
|
342
446
|
extractMimeType,
|
|
343
447
|
extractRequestData,
|
|
448
|
+
extractFetchRequestData,
|
|
344
449
|
extractResponseData,
|
|
345
450
|
}
|
|
@@ -14,6 +14,7 @@ const addresses = require('./addresses')
|
|
|
14
14
|
const {
|
|
15
15
|
startGraphqlResolver,
|
|
16
16
|
graphqlMiddlewareChannel,
|
|
17
|
+
wafRunFinished,
|
|
17
18
|
apolloHttpServerChannel,
|
|
18
19
|
apolloChannel,
|
|
19
20
|
apolloServerCoreChannel,
|
|
@@ -22,6 +23,15 @@ const { updateBlockFailureMetric } = require('./telemetry')
|
|
|
22
23
|
|
|
23
24
|
const graphqlRequestData = new WeakMap()
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Per request, the blocking action of every field checked with empty arguments or inclusion directives,
|
|
28
|
+
* including variable directives represented by `if: undefined`. Identical payloads return the same action while
|
|
29
|
+
* the request's WAF context keeps the same persistent inputs. List queries resolve the same fields once per item.
|
|
30
|
+
*
|
|
31
|
+
* @type {WeakMap<object, Map<string, object | undefined>>}
|
|
32
|
+
*/
|
|
33
|
+
const fieldsWithoutArgumentsActions = new WeakMap()
|
|
34
|
+
|
|
25
35
|
function enable () {
|
|
26
36
|
enableApollo()
|
|
27
37
|
enableGraphql()
|
|
@@ -40,19 +50,89 @@ function onGraphqlStartResolver (data) {
|
|
|
40
50
|
|
|
41
51
|
if (!req) return
|
|
42
52
|
|
|
53
|
+
const knownActions = fieldsWithoutArgumentsActions.get(req)
|
|
54
|
+
if (knownActions === undefined &&
|
|
55
|
+
!waf.wafManager.getWAFContext(req)?.knownAddresses.has(addresses.HTTP_INCOMING_GRAPHQL_RESOLVER)) return
|
|
56
|
+
|
|
43
57
|
const resolverInfo = data.createResolverInfo?.(data)
|
|
44
58
|
if (!resolverInfo || typeof resolverInfo !== 'object') return
|
|
45
59
|
|
|
46
|
-
const
|
|
60
|
+
const cacheKey = getFieldCacheKey(resolverInfo)
|
|
61
|
+
if (cacheKey !== undefined && knownActions?.has(cacheKey)) {
|
|
62
|
+
applyBlockingAction(req, data, knownActions.get(cacheKey))
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const result = waf.runSubContext({ [addresses.HTTP_INCOMING_GRAPHQL_RESOLVER]: resolverInfo })
|
|
47
67
|
const blockingAction = getBlockingAction(result?.actions)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
|
|
69
|
+
// A run that timed out, failed, or found no rule to evaluate is not an answer about the field, so let the next
|
|
70
|
+
// occurrence run again instead of reading it back as "allowed".
|
|
71
|
+
if (cacheKey !== undefined && result !== undefined && !result.timeout && !(result.errorCode < 0)) {
|
|
72
|
+
if (knownActions === undefined) {
|
|
73
|
+
const blockingActions = new Map()
|
|
74
|
+
blockingActions.set(cacheKey, blockingAction)
|
|
75
|
+
fieldsWithoutArgumentsActions.set(req, blockingActions)
|
|
76
|
+
} else {
|
|
77
|
+
knownActions.set(cacheKey, blockingAction)
|
|
54
78
|
}
|
|
55
79
|
}
|
|
80
|
+
|
|
81
|
+
applyBlockingAction(req, data, blockingAction)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Inputs stay in the request's WAF context, so they can change the action of a field checked before
|
|
86
|
+
* they arrived. Invalidate cached answers after evaluations on the request context.
|
|
87
|
+
* Resolver evaluations use subcontexts, so they never invalidate their own answers.
|
|
88
|
+
*
|
|
89
|
+
* @param {{ req?: object, payload?: object, isSubcontext?: boolean }} data
|
|
90
|
+
*/
|
|
91
|
+
function onWafRunFinished ({ req, payload, isSubcontext }) {
|
|
92
|
+
if (!req || !payload || isSubcontext) return
|
|
93
|
+
|
|
94
|
+
fieldsWithoutArgumentsActions.delete(req)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolver materializers return exactly one field.
|
|
99
|
+
*
|
|
100
|
+
* @param {Record<string, Record<string, unknown>>} resolverInfo
|
|
101
|
+
*/
|
|
102
|
+
function getFieldCacheKey (resolverInfo) {
|
|
103
|
+
const fieldName = Object.keys(resolverInfo)[0]
|
|
104
|
+
const fieldArguments = resolverInfo[fieldName]
|
|
105
|
+
const names = Object.keys(fieldArguments)
|
|
106
|
+
if (names.length === 0) return fieldName
|
|
107
|
+
|
|
108
|
+
let cacheKey = fieldName
|
|
109
|
+
for (const name of names) {
|
|
110
|
+
const directive = fieldArguments[name]
|
|
111
|
+
if ((name !== 'include' && name !== 'skip') ||
|
|
112
|
+
!directive || typeof directive !== 'object') return
|
|
113
|
+
const argumentNames = Object.keys(directive)
|
|
114
|
+
if (argumentNames.length !== 1 || argumentNames[0] !== 'if') return
|
|
115
|
+
const value = directive.if
|
|
116
|
+
if (value !== undefined && typeof value !== 'boolean') return
|
|
117
|
+
cacheKey += `:${name}:${value}`
|
|
118
|
+
}
|
|
119
|
+
return cacheKey
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @param {object} req
|
|
124
|
+
* @param {{ abortController?: AbortController }} data
|
|
125
|
+
* @param {object | undefined} blockingAction
|
|
126
|
+
*/
|
|
127
|
+
function applyBlockingAction (req, data, blockingAction) {
|
|
128
|
+
if (!blockingAction) return
|
|
129
|
+
|
|
130
|
+
const requestData = graphqlRequestData.get(req)
|
|
131
|
+
if (requestData?.isInGraphqlRequest) {
|
|
132
|
+
requestData.blocked = true
|
|
133
|
+
requestData.wafAction = blockingAction
|
|
134
|
+
data.abortController?.abort()
|
|
135
|
+
}
|
|
56
136
|
}
|
|
57
137
|
|
|
58
138
|
function enterInApolloMiddleware (data) {
|
|
@@ -161,10 +241,12 @@ function disableApollo () {
|
|
|
161
241
|
|
|
162
242
|
function enableGraphql () {
|
|
163
243
|
startGraphqlResolver.subscribe(onGraphqlStartResolver)
|
|
244
|
+
wafRunFinished.subscribe(onWafRunFinished)
|
|
164
245
|
}
|
|
165
246
|
|
|
166
247
|
function disableGraphql () {
|
|
167
248
|
if (startGraphqlResolver.hasSubscribers) startGraphqlResolver.unsubscribe(onGraphqlStartResolver)
|
|
249
|
+
if (wafRunFinished.hasSubscribers) wafRunFinished.unsubscribe(onWafRunFinished)
|
|
168
250
|
}
|
|
169
251
|
|
|
170
252
|
module.exports = {
|
|
@@ -47,9 +47,7 @@ function onExpressSession ({ req, res, sessionId, abortController }) {
|
|
|
47
47
|
if (isSdkCalled) return
|
|
48
48
|
|
|
49
49
|
const results = waf.run({
|
|
50
|
-
|
|
51
|
-
[addresses.USER_SESSION_ID]: sessionId,
|
|
52
|
-
},
|
|
50
|
+
[addresses.USER_SESSION_ID]: sessionId,
|
|
53
51
|
}, req)
|
|
54
52
|
|
|
55
53
|
handleResults(results?.actions, req, res, rootSpan, abortController)
|