-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(detectors): Handle config field updates in base detector validator #103184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(detectors): Handle config field updates in base detector validator #103184
Conversation
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
| 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
Stack trace information
Stack trace information
Stack trace information
Stack trace information
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R4 -
Copy modified lines R36-R37 -
Copy modified lines R144-R145
| @@ -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() | ||
|
|
There was a problem hiding this comment.
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
saponifi3d
left a comment
There was a problem hiding this 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!
…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
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: