Skip to content

Conversation

@kathap
Copy link
Contributor

@kathap kathap commented May 19, 2025

Wraps OpenSSL::Cipher::CipherError and TypeError in a custom EncryptorError to allow centralized handling in ApplicationController. This enables consistent 500 error responses with clearer messages like "Error while processing encrypted data".

  • A short explanation of the proposed change:
    This change wraps OpenSSL::Cipher::CipherError and TypeError raised during encryption/decryption in a custom EncryptorError exception. The ApplicationController is updated to catch this new exception.

  • An explanation of the use cases your change solves
    If a TypeError is raised by OpenSSL::PKCS5.pbkdf2_hmac (e.g., due to a nil or invalid key), or if a CipherError occurs during encryption or decryption, these are now caught and wrapped in a custom EncryptorError. This ensures the error is handled gracefully in the ApplicationController, and the user receives a standardized and meaningful 500 error response.

  • Links to any other associated PRs
    Improves Add error handling for invalid encryption keys with logging #4326

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

@kathap kathap marked this pull request as draft May 19, 2025 13:37
Wraps OpenSSL::Cipher::CipherError and TypeError in a custom EncryptorError to allow centralized handling in ApplicationController. This enables consistent 500 error responses with clearer messages like "Error while processing encrypted data".
@kathap kathap force-pushed the improve-run-cipher-error-handling branch from 02d4e62 to 8edbb87 Compare May 20, 2025 06:51
@kathap kathap marked this pull request as ready for review May 20, 2025 14:44
Copy link
Member

@tcdowney tcdowney left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but had a quick question.

message: "The UAA is currently rate limited. Please try again later"

10001:
10081:
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There exists already error with that code, I thought it would probably better to have an unique error code to identify them more easily.

@kathap kathap merged commit 503bb3f into main Jun 3, 2025
12 checks passed
ari-wg-gitbot added a commit to cloudfoundry/capi-release that referenced this pull request Jun 3, 2025
Changes in cloud_controller_ng:

- Catch CipherError and TypeError in run_cipher and raise EncryptorError
    PR: cloudfoundry/cloud_controller_ng#4365
    Author: Katharina Przybill <30441792+kathap@users.noreply.github.com>
@moleske moleske deleted the improve-run-cipher-error-handling branch June 3, 2025 15:33
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