server/src/otel/tracing.ts:636
[AGENTS: Chaos, Deadbolt, Gateway, Harbor, Lockdown, Recon, Siege, Supply, Syringe, Tenant, Weights]configuration, containers, db_injection, dos, edge_cases, edge_security, info_disclosure, model_supply_chain, sessions, supply_chain, tenant_isolation
**Perspective 1:** The OpenTelemetry implementation tracks user sessions and activities in memory maps without clear consent mechanisms or proper anonymization. This could violate privacy regulations and exposes session data in memory.
**Perspective 2:** The OpenTelemetry SDK auto-starts based on environment variables at module import time, which can cause unexpected behavior in containerized environments. The code loads .env files manually and starts the SDK before other modules load, potentially causing initialization order issues and making the application dependent on file system access at startup.
**Perspective 3:** The OpenTelemetry SDK is loaded dynamically without integrity checks or version pinning. The code imports multiple @opentelemetry packages but doesn't verify their integrity, making it vulnerable to dependency confusion attacks or compromised packages.
**Perspective 4:** The code loads environment variables from .env files using dotenv.parse() without verifying file integrity or source authenticity. This could allow an attacker to inject malicious environment variables that affect model loading behavior, such as TOOLJET_EDITION or other configuration values that control which model artifacts are loaded.
**Perspective 5:** OpenTelemetry metrics and user activity tracking stores data in shared in-memory maps (`activeUsersByWorkspace`, `activeSessionsByWorkspace`) without proper tenant isolation. While keys include workspaceId, there's no validation that metrics from one tenant can't be accessed by another tenant through the metrics API or observability tools.
**Perspective 6:** The auto-start logic in tracing.ts catches errors but only logs them. If OpenTelemetry initialization fails (e.g., due to network issues connecting to collector), the application continues without observability, making debugging production issues difficult.
**Perspective 7:** The OpenTelemetry SDK starts automatically when module is imported if ENABLE_OTEL=true. This creates instrumentations and exporters that could consume significant memory and CPU. No limits are set on span batch size, queue size, or export frequency.
**Perspective 8:** The `activeUsersByWorkspace` and `activeSessionsByWorkspace` maps have a safety cap (MAX_TRACKED_USERS) but still track user activity indefinitely within the activity window. In containerized environments with limited memory, this can lead to memory pressure and potential out-of-memory crashes if many users are active.
**Perspective 9:** The `trackUserActivity` function catches errors but only logs them in debug mode. If the function fails repeatedly (e.g., due to malformed input), it could lead to silent failures in user tracking without proper cleanup of partial data structures.
**Perspective 10:** The OpenTelemetry SDK auto-starts when the module is imported based on environment variables, without validating if the OTEL endpoints are trusted or internal. This could lead to data exfiltration if OTEL_EXPORTER_OTLP_TRACES points to an attacker-controlled endpoint.
**Perspective 11:** The OpenTelemetry auto-start feature loads multiple instrumentations (express, http, pg, pino, etc.) but there's no Software Bill of Materials tracking which versions are loaded or their dependencies. This makes vulnerability tracking and license compliance difficult.
**Perspective 12:** The code dynamically loads environment variables from .env files at runtime (lines 636-636), which can lead to non-deterministic builds. Different builds may have different configurations leading to different artifact behavior.
**Perspective 13:** The OpenTelemetry SDK auto-starts when the module is imported based on environment variables, which could bypass application initialization security checks and potentially expose tracing data before the application is fully configured.
**Perspective 14:** When OTEL_LOG_LEVEL is set to 'debug', the code logs detailed information about active user tracking, memory usage, and internal metrics to console. This includes sensitive details like workspace IDs, user counts, session counts, and memory estimates that could help attackers fingerprint the application and understand its usage patterns.
**Perspective 15:** The auto-start code logs detailed initialization information including environment variables (ENABLE_OTEL), edition checks, and SDK startup status. This information could help attackers fingerprint the deployment configuration and understand the observability setup.
**Perspective 16:** The cleanupInactiveUsers function logs memory estimates when debug mode is enabled, revealing internal memory usage patterns and data structure sizes that could help attackers understand the application's resource usage and potentially identify memory-related attack vectors.
**Perspective 17:** The default OpenTelemetry endpoint URLs (http://localhost:4318/v1/traces and http://localhost:4318/v1/metrics) are hardcoded and could reveal the observability infrastructure setup if these values are logged or exposed in error messages.
**Perspective 18:** The code dynamically loads dotenv module via require() without verifying its integrity. If an attacker can compromise the node_modules directory, they could inject malicious code into the dotenv module that affects environment variable parsing and subsequently model loading behavior.
**Perspective 19:** The `trackUserActivity` function stores user activity data in shared global maps without any access control mechanisms. While the keys include workspaceId, there's no guarantee that these maps can't be accessed across tenant boundaries through memory inspection or if the application is compromised.
**Perspective 20:** Session cleanup runs on a fixed interval (CLEANUP_INTERVAL_MS = 60 * 1000) which could be predictable. The cleanup logic also logs debug information that could leak session tracking details.
**Perspective 21:** The PgInstrumentation logs SQL queries and parameters which could expose sensitive data or injection patterns. While this is monitoring code, improper handling of query strings could lead to injection if the logs are processed or displayed without sanitization.
**Perspective 22:** The cleanup interval for inactive users is hardcoded to 60 seconds (CLEANUP_INTERVAL_MS = 60 * 1000). In containerized environments with autoscaling, this fixed interval may not be optimal for different deployment scales and could cause unnecessary CPU usage spikes.
**Perspective 23:** The OpenTelemetry configuration (exporters, headers, endpoints) is loaded from environment variables without verification of their integrity or provenance. Malicious configuration could exfiltrate sensitive tracing data.
**Perspective 24:** When debug logging is enabled, the code logs the active user tracking window configuration (ACTIVITY_WINDOW_MINUTES) which reveals the application's user activity monitoring behavior and could help attackers understand session management patterns.
**Perspective 25:** The code logs the ToolJet edition (CE, EE, Cloud) during OpenTelemetry initialization, which could help attackers fingerprint the deployment type and understand potential attack surfaces specific to each edition.
Suggested Fix
Remove the auto-start logic and initialize OTEL only when explicitly called by the application bootstrap process. Move environment variable loading to the main application initialization.