major
#29849
Configuration: an encrypted property value that is not a valid encrypted value is silently "decrypted" to garbage instead of being rejected
Context
Values of configuration properties marked with @Encrypted (e.g., passwords for database, email, or OpenAPI access) are stored in the configuration in encrypted form and decrypted using ConfigurationEncryption.decrypt when read (EncodingConfigurationValueProvider, XMLProperties.decryptValue). A value prefixed with ` unencrypted: ` is loaded unencrypted.
Problem
If a plaintext value is accidentally configured without the “unencrypted:” prefix (typically: a password from an environment variable via an alias), this is not detected in most cases:
- The AES/OFB/NoPadding encryption (SymmetricEncryption via Base64Encoder) is a stream cipher mode without integrity checking. Any byte sequence that is at least as long as the IV (16 bytes) can be “decrypted.”
- Base64.decodeBase64 silently skips characters outside the Base64 alphabet, so even values containing special characters are decoded.
- The result is converted to a string using placeholder characters, so invalid UTF-8 is also not detected.
Only if the Base64-decoded value is shorter than 16 bytes does the read operation fail with a configuration error (see #29788). A longer plaintext value is silently converted to a nonsensical value, and the application fails only later with a misleading message (e.g., login to the database or mail server denied). The actual cause—a missing ` unencrypted: ` or an incompletely copied encrypted value—cannot be determined from this.
Solution
Authenticated format for new values
- ConfigurationEncryption.encrypt writes values in a new format with authenticated encryption (AES/GCM/NoPadding, 128-bit tag). The value is prefixed with the version identifier {gcm}, followed by URL-safe Base64 encoding of the IV, ciphertext, and tag.
- ConfigurationEncryption.decrypt recognizes the format by the prefix. A value in the new format whose tag check fails (plaintext, truncated, or altered value) reliably results in a configuration error that specifies the property name but not the value (as in #29788).
- The Base64 encoding in the new format is strictly decoded: characters outside the alphabet are considered an error.
Previous format remains readable
- Values without a prefix are still read using the previous method (AES/OFB/NoPadding) so that existing configurations work without migration.
- For these values, additional validity checks have been introduced that do not require a format change: strict Base64 alphabet (a value containing characters such as !`, `#, @, or spaces is not an encoded value) and strict UTF-8 when converting the result (`CodingErrorAction.REPORT). These checks are not exhaustive (a short alphanumeric plaintext string might pass them by chance), but they cover the most common cases.
Warning for Values in the Previous Format
- When reading a value in the previous format, a warning is logged that does not specify the value, with a note to re-encode the value in the new format. For typed configuration (EncodingConfigurationValueProvider), it specifies the property name; for XMLProperties, it specifies the key and the location in the configuration file.
- This allows the values to be converted gradually. The previous format may be deprecated in a later release; only this step requires migration.
Technical Notes
- SymmetricEncryption is also used by the EncryptionService (signatures, EncryptingTransformer for encrypted database content). Its behavior and data format do not change; the authenticated method is a separate class, AuthenticatedEncryption, alongside SymmetricEncryption, and is used only by ConfigurationEncryption.
- The key for ConfigurationEncryption is a passphrase hard-coded in the source code. Therefore, the encryption protects configuration values only against accidental reading, not against someone who knows the (public) source code. This ticket does not change that; it concerns the reliable detection of invalid values.
- The maintenance page EncodeConfigurationValues.jsp, which is used to encrypt configuration values, uses ConfigurationEncryption.encrypt to generate the new format.