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
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { BLOCKER_CATEGORIES, getBlockerDomain } = require('./blocker-category')
|
|
4
|
-
const { getCommandBlocker } = require('./command-blocker')
|
|
5
|
-
const { runCommand, serializeDisplayCommand } = require('./command-runner')
|
|
6
|
-
const { getBasicCommand } = require('./runner-command')
|
|
7
|
-
const { summarizeTestOutput } = require('./scenarios/basic-reporting')
|
|
8
|
-
const { findInterestingLines, frameworkOutDir } = require('./scenarios/helpers')
|
|
9
|
-
const { getObservedTestCount } = require('./test-output')
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Runs one direct representative test without Datadog initialization.
|
|
13
|
-
*
|
|
14
|
-
* @param {object} input preflight inputs
|
|
15
|
-
* @param {object} input.framework framework manifest entry
|
|
16
|
-
* @param {string} input.out validation output directory
|
|
17
|
-
* @param {object} input.options validator options
|
|
18
|
-
* @returns {Promise<{ok: boolean, failure?: object, preflight: object}>} preflight outcome
|
|
19
|
-
*/
|
|
20
|
-
async function runFrameworkPreflight ({ framework, out, options }) {
|
|
21
|
-
const candidates = [
|
|
22
|
-
{
|
|
23
|
-
localSocketRequired: framework.localSocketRequired,
|
|
24
|
-
testFile: framework.validation.testFile,
|
|
25
|
-
},
|
|
26
|
-
...(framework.validation.fallbackTests || []),
|
|
27
|
-
]
|
|
28
|
-
const attempts = []
|
|
29
|
-
let last
|
|
30
|
-
|
|
31
|
-
for (const [index, candidate] of candidates.entries()) {
|
|
32
|
-
// Fallbacks are ordered and later candidates must not run after one succeeds.
|
|
33
|
-
// eslint-disable-next-line no-await-in-loop
|
|
34
|
-
const attempt = await runCandidate({ framework, index, options, out, testFile: candidate.testFile })
|
|
35
|
-
attempts.push(attempt.preflight)
|
|
36
|
-
last = attempt
|
|
37
|
-
if (!attempt.ok) {
|
|
38
|
-
if (isSharedCandidateBlocker(attempt.commandFailure, framework)) break
|
|
39
|
-
continue
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
framework.validation.testFile = candidate.testFile
|
|
43
|
-
const preflight = { ...attempt.preflight, attempts, selectedTestFile: candidate.testFile }
|
|
44
|
-
framework.preflight = preflight
|
|
45
|
-
return { ok: true, preflight }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const { commandFailure, observedTestCount, preflight, result } = last
|
|
49
|
-
const completePreflight = {
|
|
50
|
-
...preflight,
|
|
51
|
-
attempts,
|
|
52
|
-
selectedTestFile: undefined,
|
|
53
|
-
}
|
|
54
|
-
framework.preflight = completePreflight
|
|
55
|
-
const blockerCategory = commandFailure?.blockerCategory ||
|
|
56
|
-
(observedTestCount === 0
|
|
57
|
-
? BLOCKER_CATEGORIES.VALIDATOR_LIMITATION
|
|
58
|
-
: BLOCKER_CATEGORIES.CLEAN_TEST_FAILED)
|
|
59
|
-
const domain = getBlockerDomain(blockerCategory)
|
|
60
|
-
const diagnosis = getFailureDiagnosis(
|
|
61
|
-
result,
|
|
62
|
-
observedTestCount,
|
|
63
|
-
commandFailure,
|
|
64
|
-
preflight.diagnosticSummary,
|
|
65
|
-
framework
|
|
66
|
-
)
|
|
67
|
-
return {
|
|
68
|
-
ok: false,
|
|
69
|
-
preflight: completePreflight,
|
|
70
|
-
failure: {
|
|
71
|
-
frameworkId: framework.id,
|
|
72
|
-
scenario: 'basic-reporting',
|
|
73
|
-
status: 'blocked',
|
|
74
|
-
diagnosis,
|
|
75
|
-
evidence: {
|
|
76
|
-
blockerCategory,
|
|
77
|
-
commandFailure,
|
|
78
|
-
domain,
|
|
79
|
-
recommendation: commandFailure?.recommendation ||
|
|
80
|
-
`Resolve the selected project test failure before retrying validation: ${diagnosis}`,
|
|
81
|
-
validationIncomplete: true,
|
|
82
|
-
},
|
|
83
|
-
artifacts: Object.values(result.artifacts),
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function runCandidate ({ framework, index, options, out, testFile }) {
|
|
89
|
-
const suffix = index === 0 ? '' : `-fallback-${index}`
|
|
90
|
-
const command = getBasicCommand(framework, testFile)
|
|
91
|
-
const outDir = frameworkOutDir(out, framework, `preflight${suffix}`)
|
|
92
|
-
const result = await runCommand(command, {
|
|
93
|
-
artifactRoot: out,
|
|
94
|
-
envMode: 'clean',
|
|
95
|
-
label: `${framework.id}:preflight${suffix}`,
|
|
96
|
-
outDir,
|
|
97
|
-
repositoryRoot: options.repositoryRoot,
|
|
98
|
-
requireExecutableApproval: options.requireExecutableApproval,
|
|
99
|
-
verbose: options.verbose,
|
|
100
|
-
})
|
|
101
|
-
const observedTestCount = getObservedTestCount(framework.framework, result.stdout, result.stderr)
|
|
102
|
-
const commandFailure = getCommandBlocker(result, {
|
|
103
|
-
browserRequired: framework.browserRequired,
|
|
104
|
-
framework: framework.framework,
|
|
105
|
-
packageJson: framework.project.packageJson,
|
|
106
|
-
testsRan: Number.isInteger(observedTestCount) && observedTestCount > 0,
|
|
107
|
-
})
|
|
108
|
-
const preflight = {
|
|
109
|
-
command: serializeDisplayCommand(command),
|
|
110
|
-
diagnosticSummary: findInterestingLines(`${result.stdout}\n${result.stderr}`, [
|
|
111
|
-
/\b(?:Abort trap|Cannot find|Error|TypeError|ReferenceError|RangeError|SyntaxError|ERR_[A-Z_]+|FAIL|Failed to|No tests found|Received signal|SIGABRT)\b/i,
|
|
112
|
-
], 4),
|
|
113
|
-
durationMs: result.durationMs,
|
|
114
|
-
exitCode: result.exitCode,
|
|
115
|
-
observedTestCount,
|
|
116
|
-
ran: true,
|
|
117
|
-
selectorVerification: framework.validation.selectorScope === 'instrumented_event_identity'
|
|
118
|
-
? 'requires_instrumented_event_identity'
|
|
119
|
-
: 'bounded_direct_runner',
|
|
120
|
-
source: 'validator',
|
|
121
|
-
stderrSummary: summarizeTestOutput('', result.stderr).join('\n'),
|
|
122
|
-
stdoutSummary: summarizeTestOutput(result.stdout).join('\n'),
|
|
123
|
-
testFile,
|
|
124
|
-
timedOut: result.timedOut,
|
|
125
|
-
...(commandFailure ? { commandFailure } : {}),
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
commandFailure,
|
|
129
|
-
observedTestCount,
|
|
130
|
-
ok: !result.timedOut && result.exitCode === 0 && observedTestCount !== 0,
|
|
131
|
-
preflight,
|
|
132
|
-
result,
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Explains why direct Basic Reporting could not start reliably.
|
|
138
|
-
*
|
|
139
|
-
* @param {object} result command result
|
|
140
|
-
* @param {number|null} observedTestCount parsed test count
|
|
141
|
-
* @param {object|undefined} commandFailure classified blocker
|
|
142
|
-
* @param {string[]} diagnosticSummary bounded diagnostic lines
|
|
143
|
-
* @param {object} framework framework manifest entry
|
|
144
|
-
*/
|
|
145
|
-
function getFailureDiagnosis (result, observedTestCount, commandFailure, diagnosticSummary, framework) {
|
|
146
|
-
const sharedPrerequisite = !commandFailure && framework.allCandidatesRequireLocalSocket
|
|
147
|
-
? ' Every approved candidate appears to require localhost, so retry in the project environment where its ' +
|
|
148
|
-
'listener-based tests normally pass.'
|
|
149
|
-
: ''
|
|
150
|
-
if (commandFailure?.summary) {
|
|
151
|
-
return `${commandFailure.summary} Basic Reporting could not be tested reliably.${sharedPrerequisite}`
|
|
152
|
-
}
|
|
153
|
-
if (result.timedOut) {
|
|
154
|
-
return 'The direct representative test exceeded its approved timeout. Basic Reporting could not be tested ' +
|
|
155
|
-
'reliably; rerun the test normally and confirm its prerequisites before trying again.'
|
|
156
|
-
}
|
|
157
|
-
if (observedTestCount === 0) {
|
|
158
|
-
return 'The direct runner completed without reporting a test. The selected file may require project wrapper or ' +
|
|
159
|
-
'configuration semantics, so Basic Reporting remains incomplete.'
|
|
160
|
-
}
|
|
161
|
-
if (diagnosticSummary.length > 0) {
|
|
162
|
-
return `The direct representative test exited ${result.exitCode} without Datadog initialization. ` +
|
|
163
|
-
`The first reported issue was: ${diagnosticSummary[0]}${sharedPrerequisite}`
|
|
164
|
-
}
|
|
165
|
-
return `The direct representative test exited ${result.exitCode} without Datadog initialization. Fix or prepare ` +
|
|
166
|
-
`that test normally, then create a fresh validation plan.${sharedPrerequisite}`
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Do not try fallbacks when every disclosed candidate shares the same prerequisite.
|
|
170
|
-
function isSharedCandidateBlocker (commandFailure, framework) {
|
|
171
|
-
if (!commandFailure) return false
|
|
172
|
-
if (commandFailure.kind === 'local-test-socket-blocked') {
|
|
173
|
-
return framework.allCandidatesRequireLocalSocket === true
|
|
174
|
-
}
|
|
175
|
-
return commandFailure.kind.endsWith('-browser-launch-blocked') ||
|
|
176
|
-
[
|
|
177
|
-
'cucumber-browser-missing',
|
|
178
|
-
'cypress-runtime-missing',
|
|
179
|
-
'playwright-browser-missing',
|
|
180
|
-
'project-command-environment-missing',
|
|
181
|
-
'test-runner-command-missing',
|
|
182
|
-
'vitest-browser-provider-missing',
|
|
183
|
-
].includes(commandFailure.kind)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
module.exports = { runFrameworkPreflight }
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const path = require('node:path')
|
|
4
|
-
|
|
5
|
-
const BUILD_DIRECTORY_PATTERN = /(?:^|\/)(?:build|dist|generated)(?:\/|$)/
|
|
6
|
-
const WINDOWS_ABSOLUTE_PATH_PATTERN = /^[A-Za-z]:\//
|
|
7
|
-
|
|
8
|
-
// Bare package subpaths and node_modules paths belong to dependencies, not to the customer project.
|
|
9
|
-
function isProjectBuildArtifactPath (filename, projectRoot, baseDirectory = projectRoot) {
|
|
10
|
-
const normalized = String(filename).replaceAll('\\', '/')
|
|
11
|
-
if (!BUILD_DIRECTORY_PATTERN.test(normalized) ||
|
|
12
|
-
/(?:^|\/)node_modules(?:\/|$)/.test(normalized)) return false
|
|
13
|
-
|
|
14
|
-
const relativePath = normalized.startsWith('./') || normalized.startsWith('../')
|
|
15
|
-
if ((!relativePath && !normalized.startsWith('/') && !WINDOWS_ABSOLUTE_PATH_PATTERN.test(normalized)) ||
|
|
16
|
-
typeof projectRoot !== 'string') return false
|
|
17
|
-
|
|
18
|
-
const normalizedRoot = projectRoot.replaceAll('\\', '/')
|
|
19
|
-
const windowsPath = WINDOWS_ABSOLUTE_PATH_PATTERN.test(normalized)
|
|
20
|
-
const windowsRoot = WINDOWS_ABSOLUTE_PATH_PATTERN.test(normalizedRoot)
|
|
21
|
-
if (windowsPath !== windowsRoot && windowsPath) return false
|
|
22
|
-
const pathApi = windowsRoot ? path.win32 : path.posix
|
|
23
|
-
const root = pathApi.resolve(normalizedRoot)
|
|
24
|
-
const candidate = relativePath
|
|
25
|
-
? pathApi.resolve(String(baseDirectory).replaceAll('\\', '/'), normalized)
|
|
26
|
-
: pathApi.resolve(normalized)
|
|
27
|
-
const relative = pathApi.relative(root, candidate)
|
|
28
|
-
return relative === '' || (!relative.startsWith('..') && !pathApi.isAbsolute(relative))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = { isProjectBuildArtifactPath }
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const REDACTED = '<redacted>'
|
|
4
|
-
const MAX_SANITIZE_DEPTH = 128
|
|
5
|
-
const TRUNCATED_NESTING = '[Truncated: nesting exceeds redaction limit]'
|
|
6
|
-
|
|
7
|
-
const SECRET_NAME_SOURCE = [
|
|
8
|
-
'API_?KEY',
|
|
9
|
-
'APP_?KEY',
|
|
10
|
-
'TOKEN',
|
|
11
|
-
'SECRET',
|
|
12
|
-
'PASSWORD',
|
|
13
|
-
'PASSPHRASE',
|
|
14
|
-
'CREDENTIAL',
|
|
15
|
-
'PRIVATE_?KEY',
|
|
16
|
-
'ACCESS_?KEY',
|
|
17
|
-
'COOKIE',
|
|
18
|
-
].join('|')
|
|
19
|
-
const EXACT_SECRET_ASSIGNMENT_NAME_SOURCE = [
|
|
20
|
-
SECRET_NAME_SOURCE,
|
|
21
|
-
'AUTH',
|
|
22
|
-
'AUTHORIZATION',
|
|
23
|
-
'PASS',
|
|
24
|
-
'PAT',
|
|
25
|
-
'JWT',
|
|
26
|
-
'WEBHOOK(?:_URL)?',
|
|
27
|
-
].join('|')
|
|
28
|
-
// Every pattern built from these name sources carries the `i` flag; the classes list uppercase only.
|
|
29
|
-
const SECRET_NAME_CHARS = '[A-Z0-9_.-]'
|
|
30
|
-
const SECRET_ASSIGNMENT_NAME_SOURCE = [
|
|
31
|
-
EXACT_SECRET_ASSIGNMENT_NAME_SOURCE,
|
|
32
|
-
`[A-Z_]${SECRET_NAME_CHARS}*(?:${SECRET_NAME_SOURCE})${SECRET_NAME_CHARS}*`,
|
|
33
|
-
`[A-Z_]${SECRET_NAME_CHARS}*[-_]PASS`,
|
|
34
|
-
`[A-Z_]${SECRET_NAME_CHARS}*[-_]AUTH(?:ORIZATION)?`,
|
|
35
|
-
`[A-Z_]${SECRET_NAME_CHARS}*[-_](?:PAT|JWT|WEBHOOK(?:_URL)?)`,
|
|
36
|
-
].join('|')
|
|
37
|
-
const SECRET_FLAG_SOURCE = [
|
|
38
|
-
'api-key',
|
|
39
|
-
'app-key',
|
|
40
|
-
'token',
|
|
41
|
-
'secret',
|
|
42
|
-
'password',
|
|
43
|
-
'pass',
|
|
44
|
-
'credential',
|
|
45
|
-
'private-key',
|
|
46
|
-
'client-secret',
|
|
47
|
-
'access-key',
|
|
48
|
-
'auth',
|
|
49
|
-
].join('|')
|
|
50
|
-
const SECRET_VALUE_SOURCE = String.raw`("[^"]*"|'[^']*'|[^\s,;]+)`
|
|
51
|
-
const SENSITIVE_NAME_PATTERN = new RegExp(SECRET_NAME_SOURCE, 'i')
|
|
52
|
-
const SENSITIVE_AUTH_NAME_PATTERN = /(?:^|_)AUTH(?:ORIZATION)?(?:_|$)/i
|
|
53
|
-
const SENSITIVE_COOKIE_NAME_PATTERN = /(?:^|_)SET_?COOKIE(?:_|$)|(?:^|_)COOKIE(?:_|$)/i
|
|
54
|
-
const SENSITIVE_PASS_NAME_PATTERN = /(?:^|_)PASS(?:_|$)/i
|
|
55
|
-
const SENSITIVE_TOKEN_ALIAS_NAME_PATTERN = /(?:^|_)(?:PAT|JWT|WEBHOOK(?:_URL)?)(?:_|$)/i
|
|
56
|
-
const SECRET_ASSIGNMENT_PATTERN = new RegExp(
|
|
57
|
-
String.raw`\b(${SECRET_ASSIGNMENT_NAME_SOURCE})\s*=\s*` + SECRET_VALUE_SOURCE,
|
|
58
|
-
'gi'
|
|
59
|
-
)
|
|
60
|
-
const SECRET_FLAG_PATTERN = new RegExp(
|
|
61
|
-
String.raw`(--(?:${SECRET_FLAG_SOURCE})(?:-[A-Z0-9]+)*)(=|\s+)` + SECRET_VALUE_SOURCE,
|
|
62
|
-
'gi'
|
|
63
|
-
)
|
|
64
|
-
const SECRET_FLAG_NAME_PATTERN = new RegExp(
|
|
65
|
-
`^--(?:${SECRET_FLAG_SOURCE})(?:-[A-Z0-9]+)*$`,
|
|
66
|
-
'i'
|
|
67
|
-
)
|
|
68
|
-
const AUTH_HEADER_PATTERN = /\b(Bearer)\s+([^\s'",}\]]+)/gi
|
|
69
|
-
const AUTH_SCHEME_ASSIGNMENT_QUOTED_PATTERN = new RegExp(
|
|
70
|
-
String.raw`\b(${SECRET_ASSIGNMENT_NAME_SOURCE})\s*=\s*(["'])(?:Bearer|Basic)\s.*?\2`,
|
|
71
|
-
'gi'
|
|
72
|
-
)
|
|
73
|
-
const AUTH_SCHEME_ASSIGNMENT_PATTERN = new RegExp(
|
|
74
|
-
String.raw`\b(${SECRET_ASSIGNMENT_NAME_SOURCE})\s*=\s*(?:Bearer|Basic)\s+[^\s,;]+`,
|
|
75
|
-
'gi'
|
|
76
|
-
)
|
|
77
|
-
const DEFAULT_IGNORABLE_PATTERN = /\p{Default_Ignorable_Code_Point}/gu
|
|
78
|
-
const DEFAULT_IGNORABLE_TEST_PATTERN = /\p{Default_Ignorable_Code_Point}/u
|
|
79
|
-
const CONTROL_CHARACTER_TEST_PATTERN = /\p{Cc}/u
|
|
80
|
-
const UNSAFE_CONTROL_SOURCE = String.raw`[\u0000-\u0008\v\f\u000E-\u001F\u007F-\u009F]`
|
|
81
|
-
const UNSAFE_CONTROL_PATTERN = new RegExp(UNSAFE_CONTROL_SOURCE, 'g')
|
|
82
|
-
const UNSAFE_CONTROL_TEST_PATTERN = new RegExp(UNSAFE_CONTROL_SOURCE)
|
|
83
|
-
const PRIVATE_KEY_BLOCK_PATTERN =
|
|
84
|
-
/-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/g
|
|
85
|
-
const JWT_VALUE_PATTERN = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g
|
|
86
|
-
const KNOWN_TOKEN_VALUE_PATTERN =
|
|
87
|
-
/\b(?:gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{20,})\b/g
|
|
88
|
-
const SECRET_HEADER_ENV_NAME_SOURCE = [
|
|
89
|
-
`${SECRET_NAME_SOURCE}|PAT|JWT|WEBHOOK(?:_URL)?`,
|
|
90
|
-
`[A-Z_]${SECRET_NAME_CHARS}*(?:${SECRET_NAME_SOURCE})${SECRET_NAME_CHARS}*`,
|
|
91
|
-
`[A-Z_]${SECRET_NAME_CHARS}*[-_]AUTH(?:ORIZATION)?`,
|
|
92
|
-
`[A-Z_]${SECRET_NAME_CHARS}*[-_](?:PAT|JWT|WEBHOOK(?:_URL)?)`,
|
|
93
|
-
].join('|')
|
|
94
|
-
const SECRET_HEADER_NAME_SOURCE = [
|
|
95
|
-
'dd-api-key',
|
|
96
|
-
'x-api-key',
|
|
97
|
-
'api-key',
|
|
98
|
-
'authorization',
|
|
99
|
-
'proxy-authorization',
|
|
100
|
-
SECRET_HEADER_ENV_NAME_SOURCE,
|
|
101
|
-
].join('|')
|
|
102
|
-
const SECRET_HEADER_PATTERN = new RegExp(
|
|
103
|
-
String.raw`\b(${SECRET_HEADER_NAME_SOURCE})\s*:\s*("[^"]*"|'[^']*'|[^\r\n,}]+)`,
|
|
104
|
-
'gi'
|
|
105
|
-
)
|
|
106
|
-
const URL_CREDENTIAL_PATTERN = /(?<![a-z0-9+.-])([a-z][a-z0-9+.-]*:\/\/)([^@\s/]+)(@)/gi
|
|
107
|
-
const GITHUB_SECRET_REFERENCE_PATTERN =
|
|
108
|
-
/(?:\b[A-Za-z_][A-Za-z0-9_.-]*\s*[:=]\s*)?\$\{\{\s*secrets\.([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g
|
|
109
|
-
const SAFE_REFERENCE_MARKER_PATTERN = /DDCIVARREF([0-9]+)X/g
|
|
110
|
-
|
|
111
|
-
const ENV_CONTAINER_KEYS = new Set([
|
|
112
|
-
'safeEnv',
|
|
113
|
-
'workflowEnv',
|
|
114
|
-
'jobEnv',
|
|
115
|
-
'stepEnv',
|
|
116
|
-
'inheritedEnv',
|
|
117
|
-
])
|
|
118
|
-
|
|
119
|
-
const SECRET_NAME_ONLY_KEYS = new Set([
|
|
120
|
-
'requiredEnvVars',
|
|
121
|
-
'requiredSecretEnvVars',
|
|
122
|
-
'secretEnvVars',
|
|
123
|
-
'missingEnvVars',
|
|
124
|
-
'originalSecretEnvVars',
|
|
125
|
-
])
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Redacts secret-like values from arbitrary report data before it is serialized.
|
|
129
|
-
*
|
|
130
|
-
* @param {unknown} value data to sanitize
|
|
131
|
-
* @returns {unknown} sanitized copy
|
|
132
|
-
*/
|
|
133
|
-
function sanitizeForReport (value) {
|
|
134
|
-
return sanitizeValue(value, new WeakSet(), undefined, 0)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Redacts secret-like values from an environment variable map.
|
|
139
|
-
*
|
|
140
|
-
* @param {object|undefined} env environment map
|
|
141
|
-
* @returns {object|undefined} sanitized environment map
|
|
142
|
-
*/
|
|
143
|
-
function sanitizeEnv (env) {
|
|
144
|
-
if (!env || typeof env !== 'object' || Array.isArray(env)) return
|
|
145
|
-
|
|
146
|
-
const sanitized = {}
|
|
147
|
-
for (const [name, value] of Object.entries(env)) {
|
|
148
|
-
sanitized[name] = sanitizeEnvValue(name, value)
|
|
149
|
-
}
|
|
150
|
-
if (Object.keys(sanitized).length > 0) return sanitized
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Redacts a single environment value when its name is secret-like.
|
|
155
|
-
*
|
|
156
|
-
* @param {string} name environment variable name
|
|
157
|
-
* @param {unknown} value environment variable value
|
|
158
|
-
* @returns {string|undefined} sanitized environment variable value
|
|
159
|
-
*/
|
|
160
|
-
function sanitizeEnvValue (name, value) {
|
|
161
|
-
if (isSensitiveName(name)) return REDACTED
|
|
162
|
-
if (value === undefined) return
|
|
163
|
-
return sanitizeString(String(value))
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Redacts common inline secret forms from strings.
|
|
168
|
-
*
|
|
169
|
-
* @param {string} value string to sanitize
|
|
170
|
-
*/
|
|
171
|
-
function sanitizeString (value) {
|
|
172
|
-
const references = []
|
|
173
|
-
const protectedValue = value.replaceAll(GITHUB_SECRET_REFERENCE_PATTERN, reference => {
|
|
174
|
-
return `DDCIVARREF${references.push(reference) - 1}X`
|
|
175
|
-
})
|
|
176
|
-
const sanitized = protectedValue
|
|
177
|
-
.replaceAll(DEFAULT_IGNORABLE_PATTERN, '')
|
|
178
|
-
.replaceAll(UNSAFE_CONTROL_PATTERN, '')
|
|
179
|
-
.replaceAll(PRIVATE_KEY_BLOCK_PATTERN, '<redacted-private-key>')
|
|
180
|
-
.replaceAll(JWT_VALUE_PATTERN, REDACTED)
|
|
181
|
-
.replaceAll(KNOWN_TOKEN_VALUE_PATTERN, REDACTED)
|
|
182
|
-
.replaceAll(AUTH_SCHEME_ASSIGNMENT_QUOTED_PATTERN, `$1=${REDACTED}`)
|
|
183
|
-
.replaceAll(AUTH_SCHEME_ASSIGNMENT_PATTERN, `$1=${REDACTED}`)
|
|
184
|
-
.replaceAll(SECRET_ASSIGNMENT_PATTERN, `$1=${REDACTED}`)
|
|
185
|
-
.replaceAll(SECRET_FLAG_PATTERN, `$1$2${REDACTED}`)
|
|
186
|
-
.replaceAll(SECRET_HEADER_PATTERN, `$1: ${REDACTED}`)
|
|
187
|
-
.replaceAll(AUTH_HEADER_PATTERN, `$1 ${REDACTED}`)
|
|
188
|
-
.replaceAll(URL_CREDENTIAL_PATTERN, `$1${REDACTED}$3`)
|
|
189
|
-
|
|
190
|
-
return sanitized.replaceAll(SAFE_REFERENCE_MARKER_PATTERN, (marker, index) => references[Number(index)] || marker)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Detects default-ignorable Unicode characters that can conceal executable text or secret names.
|
|
195
|
-
*
|
|
196
|
-
* @param {unknown} value candidate text
|
|
197
|
-
*/
|
|
198
|
-
function hasUnicodeDefaultIgnorable (value) {
|
|
199
|
-
return DEFAULT_IGNORABLE_TEST_PATTERN.test(String(value))
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function hasUnsafeInvisibleCharacter (value) {
|
|
203
|
-
const text = String(value)
|
|
204
|
-
return hasUnicodeDefaultIgnorable(text) || UNSAFE_CONTROL_TEST_PATTERN.test(text)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function hasUnsafeExecutionCharacter (value) {
|
|
208
|
-
return hasUnicodeDefaultIgnorable(value) || CONTROL_CHARACTER_TEST_PATTERN.test(String(value ?? ''))
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Makes untrusted text safe to print to an interactive terminal while preserving line breaks.
|
|
213
|
-
*
|
|
214
|
-
* @param {unknown} value console value
|
|
215
|
-
*/
|
|
216
|
-
function sanitizeConsoleText (value) {
|
|
217
|
-
let result = ''
|
|
218
|
-
for (const character of sanitizeString(String(value ?? ''))) {
|
|
219
|
-
const code = character.charCodeAt(0)
|
|
220
|
-
result += character === '\n' || character === '\t' || code > 0x1F && code !== 0x7F
|
|
221
|
-
? character
|
|
222
|
-
: String.raw`\u${code.toString(16).padStart(4, '0')}`
|
|
223
|
-
}
|
|
224
|
-
return result
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Returns whether a key or variable name usually carries secret values.
|
|
229
|
-
*
|
|
230
|
-
* @param {string} name key or environment variable name
|
|
231
|
-
*/
|
|
232
|
-
function isSensitiveName (name) {
|
|
233
|
-
const normalized = name.replaceAll(/[-.]/g, '_')
|
|
234
|
-
return SENSITIVE_NAME_PATTERN.test(normalized) ||
|
|
235
|
-
SENSITIVE_AUTH_NAME_PATTERN.test(normalized) ||
|
|
236
|
-
SENSITIVE_COOKIE_NAME_PATTERN.test(normalized) ||
|
|
237
|
-
SENSITIVE_PASS_NAME_PATTERN.test(normalized) ||
|
|
238
|
-
SENSITIVE_TOKEN_ALIAS_NAME_PATTERN.test(normalized)
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function sanitizeValue (value, seen, key, depth) {
|
|
242
|
-
if (typeof value === 'string') {
|
|
243
|
-
if (key && isSensitiveName(key) && !SECRET_NAME_ONLY_KEYS.has(key)) return REDACTED
|
|
244
|
-
return sanitizeString(value)
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (value === null || typeof value !== 'object') return value
|
|
248
|
-
if (depth > MAX_SANITIZE_DEPTH) return TRUNCATED_NESTING
|
|
249
|
-
if (seen.has(value)) return '[Circular]'
|
|
250
|
-
seen.add(value)
|
|
251
|
-
|
|
252
|
-
if (Array.isArray(value)) {
|
|
253
|
-
const sanitized = sanitizeArray(value, seen, key, depth)
|
|
254
|
-
seen.delete(value)
|
|
255
|
-
return sanitized
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (key && ENV_CONTAINER_KEYS.has(key)) {
|
|
259
|
-
const env = sanitizeEnv(value)
|
|
260
|
-
seen.delete(value)
|
|
261
|
-
return env || {}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const sanitized = {}
|
|
265
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
266
|
-
if (isSensitiveName(entryKey) && !SECRET_NAME_ONLY_KEYS.has(entryKey) &&
|
|
267
|
-
typeof entryValue !== 'boolean') {
|
|
268
|
-
sanitized[entryKey] = REDACTED
|
|
269
|
-
continue
|
|
270
|
-
}
|
|
271
|
-
sanitized[entryKey] = sanitizeValue(entryValue, seen, entryKey, depth + 1)
|
|
272
|
-
}
|
|
273
|
-
seen.delete(value)
|
|
274
|
-
return sanitized
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Redacts secret flag/value pairs in arrays such as argv before sanitizing nested values.
|
|
279
|
-
*
|
|
280
|
-
* @param {Array<unknown>} value array to sanitize
|
|
281
|
-
* @param {WeakSet<object>} seen objects currently being sanitized
|
|
282
|
-
* @param {string|undefined} key parent key
|
|
283
|
-
* @param {number} depth current nesting depth
|
|
284
|
-
* @returns {Array<unknown>} sanitized array
|
|
285
|
-
*/
|
|
286
|
-
function sanitizeArray (value, seen, key, depth) {
|
|
287
|
-
const sanitized = []
|
|
288
|
-
|
|
289
|
-
for (let index = 0; index < value.length; index++) {
|
|
290
|
-
const item = value[index]
|
|
291
|
-
if (typeof item === 'string' && SECRET_FLAG_NAME_PATTERN.test(item) && index + 1 < value.length) {
|
|
292
|
-
sanitized.push(sanitizeString(item))
|
|
293
|
-
if (!isFlagToken(value[index + 1])) {
|
|
294
|
-
sanitized.push(REDACTED)
|
|
295
|
-
index++
|
|
296
|
-
}
|
|
297
|
-
continue
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
sanitized.push(sanitizeValue(item, seen, key, depth + 1))
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return sanitized
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function isFlagToken (value) {
|
|
307
|
-
return typeof value === 'string' && /^-{1,2}\S/.test(value)
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
module.exports = {
|
|
311
|
-
hasUnsafeExecutionCharacter,
|
|
312
|
-
hasUnsafeInvisibleCharacter,
|
|
313
|
-
isSensitiveName,
|
|
314
|
-
sanitizeConsoleText,
|
|
315
|
-
sanitizeEnv,
|
|
316
|
-
sanitizeEnvValue,
|
|
317
|
-
sanitizeForReport,
|
|
318
|
-
sanitizeString,
|
|
319
|
-
}
|