8000 Decryption of submission via managed keys by kelvin-muchiri · Pull Request #2789 · onaio/onadata · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Decryption of submission via managed keys #2789

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

Merged
merged 272 commits into from
Jul 9, 2025
Merged

Conversation

kelvin-muchiri
Copy link
Contributor
@kelvin-muchiri kelvin-muchiri commented Apr 2, 2025

Changes/Features implemented

Encryption of XForms using managed keys.
Decryption of submissions of XForms using managed keys.
Management of encryption keys via key management service provider API.

Steps taken to verify this change does what is intended

  • QA

Side effects of implementing this change

No side effects

Before submitting this PR for review, please make sure you have:

  • Included tests
  • Updated documentation

Closes #

@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from ca5f31a to 42c206f Compare April 2, 2025 15:35
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from 81c717a to 1343c28 Compare April 9, 2025 11:19

except EncryptionError as exc:
raise serializers.ValidationError(
{"enable_kms_encryption": f"{exc}"}

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.

Copilot Autofix

AI 30 days ago

To fix the issue, the exception message (exc) should be replaced with a generic error message that does not reveal sensitive information. The detailed exception can still be logged on the server for debugging purposes. This ensures that developers retain access to the stack trace while protecting end users from seeing sensitive details.

The changes should be made in the update method of the XFormSerializer class. Specifically:

  1. Replace the detailed exception message (f"{exc}") with a generic error message like "An error occurred while enabling KMS encryption.".
  2. Log the original exception (exc) using the logging module to retain debugging information.
Suggested changeset 1
onadata/libs/serializers/xform_serializer.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/onadata/libs/serializers/xform_serializer.py b/onadata/libs/serializers/xform_serializer.py
--- a/onadata/libs/serializers/xform_serializer.py
+++ b/onadata/libs/serializers/xform_serializer.py
@@ -610,4 +610,5 @@
                 except EncryptionError as exc:
+                    logging.error(f"EncryptionError occurred: {exc}")
                     raise serializers.ValidationError(
-                        {"enable_kms_encryption": f"{exc}"}
+                        {"enable_kms_encryption": "An error occurred while enabling KMS encryption."}
                     )
@@ -625,4 +626,5 @@
                 except EncryptionError as exc:
+                    logging.error(f"EncryptionError occurred: {exc}")
                     raise serializers.ValidationError(
-                        {"enable_kms_encryption": f"{exc}"}
+                        {"enable_kms_encryption": "An error occurred while disabling KMS encryption."}
                     )
EOF
@@ -610,4 +610,5 @@
except EncryptionError as exc:
logging.error(f"EncryptionError occurred: {exc}")
raise serializers.ValidationError(
{"enable_kms_encryption": f"{exc}"}
{"enable_kms_encryption": "An error occurred while enabling KMS encryption."}
)
@@ -625,4 +626,5 @@
except EncryptionError as exc:
logging.error(f"EncryptionError occurred: {exc}")
raise serializers.ValidationError(
{"enable_kms_encryption": f"{exc}"}
{"enable_kms_encryption": "An error occurred while disabling KMS encryption."}
)
Copilot is powered by AI and may make mistakes. Always verify output.
@kelvin-muchiri kelvin-muchiri marked this pull request as ready for review April 10, 2025 13:20
@kelvin-muchiri kelvin-muchiri marked this pull request as draft April 10, 2025 13:31
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from ed09fb5 to 53b4c03 Compare April 15, 2025 09:43
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch 3 times, most recently from 0ed265c to e6559a4 Compare May 6, 2025 13:56
rotation_reason=self.validated_data.get("rotation_reason"),
)
except EncryptionError as exc:
raise serializers.ValidationError({"id": f"{exc}"})

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.

Copilot Autofix

AI 2 months ago

To fix the issue, we will replace the direct exposure of the exception message with a generic error message for the user. The detailed exception information will be logged on the server for debugging purposes. This ensures that sensitive information is not exposed to external users while still allowing developers to diagnose issues.

Suggested changeset 1
onadata/libs/serializers/organization_serializer.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/onadata/libs/serializers/organization_serializer.py b/onadata/libs/serializers/organization_serializer.py
--- a/onadata/libs/serializers/organization_serializer.py
+++ b/onadata/libs/serializers/organization_serializer.py
@@ -241,2 +241,7 @@
         except EncryptionError as exc:
-            raise serializers.ValidationError({"id": f"{exc}"})
+            import logging
+            logger = logging.getLogger(__name__)
+            logger.error("Encryption error during key rotation: %s", exc)
+            raise serializers.ValidationError(
+                {"id": _("An internal error occurred while processing the request.")}
+            )
EOF
@@ -241,2 +241,7 @@
except EncryptionError a 8000 s exc:
raise serializers.ValidationError({"id": f"{exc}"})
import logging
logger = logging.getLogger(__name__)
logger.error("Encryption error during key rotation: %s", exc)
raise serializers.ValidationError(
{"id": _("An internal error occurred while processing the request.")}
)
Copilot is powered by AI and may make mistakes. Always verify output.
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch 2 times, most recently from eac9423 to 412613d Compare May 19, 2025 07:04
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from 84cf78e to 8db3793 Compare June 3, 2025 08:47
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from 9ad3dd3 to ccee366 Compare June 11, 2025 08:47
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from 1bcd435 to aa9ca4a Compare June 18, 2025 11:15
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from 4832992 to 6483396 Compare July 7, 2025 06:48
@kelvin-muchiri kelvin-muchiri requested a review from ukanga July 7, 2025 07:27
@kelvin-muchiri kelvin-muchiri marked this pull request as ready for review July 7, 2025 07:27
8000
kelvin-muchiri and others added 26 commits July 9, 2025 09:27
…soft delete (#2844)

* use pre_save to decr num_of_decrypted_submissions on Instance soft delete

* rename signal handler

* refactor code

* update docstring
* add task for sending grace period expiry reminder notification

* add support for multiple grace period reminders

* enhance validation for setting KMS_GRACE_EXPIRY_REMINDER_DURATION

* enhance comment

* resolve lint error possibly-used-before-assignment
* refactor code

* fix failing tests

* decrement EntityList num_entities if Entity.soft_delete is by-passed

decrement EntiyList num_entities even if deleted_at is set directly
* install valigetta package

* strip extras for pip-compile

* install valigetta via https
* add management command to create org encryption key

* update module docstrings

* resolve lint error line too long
@kelvin-muchiri kelvin-muchiri force-pushed the valigetta-integration branch from 6483396 to 0981b69 Compare July 9, 2025 06:31
@kelvin-muchiri kelvin-muchiri merged commit a2ca933 into main Jul 9, 2025
10 of 11 checks passed
@kelvin-muchiri kelvin-muchiri deleted the valigetta-integration branch July 9, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0