-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Ridheshdabhi/fix plugin store credentials in base64 15718 #116549
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,11 @@ | |
| import re | ||
| from urllib.parse import parse_qs, quote_plus, unquote_plus, urlencode, urlsplit, urlunsplit | ||
|
|
||
| from django.conf import settings | ||
| from django.urls import re_path | ||
| from rest_framework.request import Request | ||
| from rest_framework.response import Response | ||
|
|
||
| from sentry.db.models.fields.encryption import EncryptedTextField | ||
| from sentry.exceptions import PluginError | ||
| from sentry.integrations.base import FeatureDescription, IntegrationFeatures | ||
| from sentry.models.groupmeta import GroupMeta | ||
|
|
@@ -44,6 +44,30 @@ class JiraPlugin(CorePluginMixin, IssuePlugin2): | |
| IntegrationFeatures.ISSUE_BASIC, | ||
| ) | ||
| ] | ||
| _password_field = EncryptedTextField() | ||
|
|
||
| def set_option(self, key, value, project=None, user=None) -> None: | ||
| if key == "password" and isinstance(value, str) and value: | ||
| # Avoid re-encrypting already-encrypted values. | ||
| if not value.startswith("enc:"): | ||
| value = self._password_field.get_prep_value(value) | ||
| super().set_option(key, value, project=project, user=user) | ||
|
|
||
| def get_option(self, key, project=None, user=None): | ||
| value = super().get_option(key, project=project, user=user) | ||
| if key != "password" or not isinstance(value, str) or not value: | ||
| return value | ||
|
|
||
| try: | ||
| decrypted = self._password_field.to_python(value) | ||
| if isinstance(decrypted, bytes): | ||
| return decrypted.decode("utf-8") | ||
| return decrypted | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failed decrypt returns ciphertext passwordMedium Severity
Reviewed by Cursor Bugbot for commit a65e6ef. Configure here. |
||
| except Exception: | ||
| logger.warning( | ||
| "jira.password.decrypt.failed", extra={"project_id": getattr(project, "id", None)} | ||
| ) | ||
| return None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing settings import crashes post_processMedium Severity This change removes the Reviewed by Cursor Bugbot for commit a65e6ef. Configure here. |
||
|
|
||
| def get_group_urls(self): | ||
| _patterns = super().get_group_urls() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from sentry.db.models.fields.encryption import EncryptedJSONField | ||
| from sentry.integrations.models.integration import Integration | ||
| from sentry.testutils.cases import TestCase | ||
|
|
||
|
|
||
| class IntegrationSecurityTest(TestCase): | ||
| def test_metadata_field_is_encrypted_json(self) -> None: | ||
| assert isinstance(Integration._meta.get_field("metadata"), EncryptedJSONField) |


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.
Bug: Changing the default encryption method to
fernetwill cause crashes in existing deployments that haven't configured Fernet keys, as any write to an encrypted field will fail.Severity: CRITICAL
Suggested Fix
Revert the default value for
database.encryption.methodto"plaintext"in bothserver.pyandoptions/defaults.py. This will maintain backward compatibility for existing deployments. The change tofernetshould be an opt-in configuration for users who have set up the required Fernet encryption keys.Prompt for AI Agent
Also affects:
src/sentry_plugins/jira/plugin.py:49Did we get this right? 👍 / 👎 to inform future reviews.