Skip to content

Conversation

@evanpurkhiser
Copy link
Member

Previously, the base detector validator update() method did not handle config field updates at all. This adds proper support for updating the config field with JSON schema validation using enforce_config_schema().

Adds tests to verify:

  • Valid config updates are applied correctly
  • Invalid config updates that violate the schema are rejected with appropriate error messages

Previously, the base detector validator update() method did not handle
config field updates at all. This adds proper support for updating the
config field with JSON schema validation using enforce_config_schema().

Adds tests to verify:
- Valid config updates are applied correctly
- Invalid config updates that violate the schema are rejected with
  appropriate error messages
@evanpurkhiser evanpurkhiser requested a review from a team as a code owner November 11, 2025 21:45
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 11, 2025
@evanpurkhiser evanpurkhiser requested review from a team, kcons, saponifi3d and wedamija November 11, 2025 21:45
try:
enforce_config_schema(instance)
except JSONSchemaValidationError as error:
raise serializers.ValidationError({"config": [str(error)]})

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 1 day ago

To fix the problem, we need to suppress the detailed exception information from being exposed to external users. Instead of passing str(error) (which may contain stack trace, schema internals, or other sensitive info) to the user via serializers.ValidationError, we should replace it with a generic error message like "Invalid configuration." At the same time, we should log the full error internally (using Python's logging facilities) so developers can still trace and debug misconfigurations. This requires adding a logger to the file (via Python's logging module) and modifying the exception handler to log error or its stack trace before raising the generic error. The required changes are limited to the update method in src/sentry/workflow_engine/endpoints/validators/base/detector.py, specifically the lines inside the config validation exception handler.

Suggested changeset 1
src/sentry/workflow_engine/endpoints/validators/base/detector.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/sentry/workflow_engine/endpoints/validators/base/detector.py b/src/sentry/workflow_engine/endpoints/validators/base/detector.py
--- a/src/sentry/workflow_engine/endpoints/validators/base/detector.py
+++ b/src/sentry/workflow_engine/endpoints/validators/base/detector.py
@@ -1,7 +1,7 @@
 import builtins
 from dataclasses import dataclass
 from typing import Any
-
+import logging
 from django.db import router, transaction
 from jsonschema import ValidationError as JSONSchemaValidationError
 from rest_framework import serializers
@@ -33,6 +33,8 @@
 from sentry.workflow_engine.types import DataConditionType
 
 
+logger = logging.getLogger(__name__)
+
 @dataclass(frozen=True)
 class DetectorQuota:
     has_exceeded: bool
@@ -139,7 +141,8 @@
                 try:
                     enforce_config_schema(instance)
                 except JSONSchemaValidationError as error:
-                    raise serializers.ValidationError({"config": [str(error)]})
+                    logger.exception("Config schema validation failed for Detector %s", instance.id)
+                    raise serializers.ValidationError({"config": ["Invalid configuration."]})
 
             instance.save()
 
EOF
@@ -1,7 +1,7 @@
import builtins
from dataclasses import dataclass
from typing import Any

import logging
from django.db import router, transaction
from jsonschema import ValidationError as JSONSchemaValidationError
from rest_framework import serializers
@@ -33,6 +33,8 @@
from sentry.workflow_engine.types import DataConditionType


logger = logging.getLogger(__name__)

@dataclass(frozen=True)
class DetectorQuota:
has_exceeded: bool
@@ -139,7 +141,8 @@
try:
enforce_config_schema(instance)
except JSONSchemaValidationError as error:
raise serializers.ValidationError({"config": [str(error)]})
logger.exception("Config schema validation failed for Detector %s", instance.id)
raise serializers.ValidationError({"config": ["Invalid configuration."]})

instance.save()

Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we were doing the validation in the create as well

@evanpurkhiser evanpurkhiser changed the title ref(detectors): Handle config field updates in base detector validator feat(detectors): Handle config field updates in base detector validator Nov 11, 2025
Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 - now configs update. thanks!

@evanpurkhiser evanpurkhiser merged commit 4b6977c into master Nov 12, 2025
68 checks passed
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-detectors-handle-config-field-updates-in-base-detector-validator branch November 12, 2025 17:59
andrewshie-sentry pushed a commit that referenced this pull request Nov 13, 2025
…or (#103184)

Previously, the base detector validator update() method did not handle
config field updates at all. This adds proper support for updating the
config field with JSON schema validation using enforce_config_schema().

Adds tests to verify:
- Valid config updates are applied correctly
- Invalid config updates that violate the schema are rejected with
appropriate error messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants