Skip to content
Disconf Auto-Decryption: Fixing Hot-Update Ciphertext Leakage

Disconf Auto-Decryption: Fixing Hot-Update Ciphertext Leakage

The article details implementing automatic decryption for sensitive Disconf configurations by extending Spring's PropertyPlaceholderConfigurer, revealing why hot updates bypassed decryption and how overriding mergeProperties ensures consistent decryption at startup and runtime.

WeiLi Technology Team
WeiLi Technology Team
WeiLi Technology Team

Why Encrypt Disconf Configs?

Disconf often stores sensitive values like AK, SK, and API keys. Previously these were plaintext, which made config changes easy but exposed secrets to anyone with access to the Disconf console, repositories, or download directories.

Goals

Store only ciphertext in Disconf.

Business code continues to use @Value("${xxx}") without manual decryption.

Both startup and hot updates decrypt consistently.

Conclusion First

Disconf managed configuration relies on Spring's PropertyPlaceholderConfigurer. At startup, Spring calls convertProperties then parses ${}, so overriding convertPropertyValue enables decryption. However, hot updates take a different path: Disconf directly uses the return value of mergeProperties() to update beans via BeanWrapper.setPropertyValue, bypassing convertProperties. Therefore, a custom Configurer must do two things:

Override convertPropertyValue to detect and decrypt ciphertext.

Override mergeProperties to call convertProperties immediately after merging, ensuring hot updates also receive plaintext.

The convention is simple: ciphertext values end with _encrypted; values without this suffix are returned as-is.

Integration Steps

1. Replace Configurer in XML

Originally using Disconf's ReloadingPropertyPlaceholderConfigurer. Replace with a custom subclass:

<bean id="application_Properties"
     class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
  <property name="locationPaths">
    <list>
      <value>classpath:*/xxx1.properties</value>
      <value>classpath:*/xxx2.properties</value>
      <!-- other managed files -->
    </list>
  </property>
</bean>

<bean id="applicationPropertyConfigurer"
     class="weli.spring.config.ReloadingEncryptedPropertyPlaceholderConfigurer">
  <property name="ignoreUnresolvablePlaceholders" value="true"/>
  <property name="propertiesArray">
    <list>
      <ref bean="application_Properties"/>
    </list>
  </property>
</bean>

Sensitive configs go into separate xxx.properties files managed by Disconf in encrypted form; ordinary switches and whitelists remain in plaintext files.

2. Custom ReloadingEncryptedPropertyPlaceholderConfigurer

Core methods:

public class ReloadingEncryptedPropertyPlaceholderConfigurer
        extends ReloadingPropertyPlaceholderConfigurer {

    private static final String ENCRYPTED_SUFFIX = "_encrypted";

    /**
     * Disconf hot update uses mergeProperties() return value directly to update beans,
     * without going through Spring startup's convertProperties.
     * Decrypt immediately after merge so hot updates match startup behavior.
     */
    @Override
    protected Properties mergeProperties() throws IOException {
        Properties properties = super.mergeProperties();
        convertProperties(properties);
        return properties;
    }

    @Override
    protected String convertPropertyValue(String originalValue) {
        if (!StringUtils.endsWith(originalValue, ENCRYPTED_SUFFIX)) {
            return originalValue;
        }
        String cipherText = originalValue.substring(
                0, originalValue.length() - ENCRYPTED_SUFFIX.length());
        return KmsAesUtils.decrypt(cipherText, resolveEncryptKey());
    }
}

Business code remains unchanged. For example:

@Value("${volc.ai.apiKey}")
private String volcApiKey;

The field receives plaintext.

3. Disconf Configuration Format

Encrypted values follow the format: {Base64Ciphertext}_encrypted Example:

# Plaintext era
volc.ai.apiKey=sk-xxxxxxxx

# After encryption
volc.ai.apiKey=AbCdEf....==_encrypted

Detection relies on the suffix, not the key name. Plaintext and ciphertext can coexist in the same file. Switches remain 1 / 0; only secrets get the _encrypted suffix. Decryption uses a unified KMS AES utility; the decryption key must not be hardcoded in blogs or committed to Git in plaintext. In production, retrieve from KMS or controlled configuration.

Post-Deployment Issue: Startup Decrypts, Hot Update Doesn't

Integration was straightforward: custom Configurer overriding convertPropertyValue. After Spring-style integration, startup and restart validation passed: @Value received plaintext and downstream SDKs worked.

After deployment, a colleague changed an encrypted config in Disconf. Hot update took effect, but the bean field became ciphertext like xxxx_encrypted. Downstream calls with the ciphertext failed. Restarting the service restored normal behavior. In other words: restarting never reveals the issue; changing config writes ciphertext into memory.

The decryption logic wasn't wrong; hot update simply didn't pass through decryption.

Root Cause Analysis

Spring's PropertyPlaceholderConfigurer inherits from PropertyResourceConfigurer. Startup flow roughly:

postProcessBeanFactory
 ├─ mergeProperties()          // merge local files and Disconf downloaded files into one Properties
 ├─ convertProperties()        // iterate each value, call convertPropertyValue
 └─ processProperties()        // parse ${}, inject into beans
convertProperties

passes each value to convertPropertyValue. At startup, overriding this method decrypts ciphertext before placeholder parsing, so restart validation passes.

The problem lies in hot updates. Disconf's ReloadingPropertyPlaceholderConfigurer implements IReloadablePropertiesListener. On config change, it invokes propertiesReloaded:

Config file change
 └─ propertiesReloaded()
      ├─ retrieve lastMergedProperties (old values)
      ├─ call mergeProperties() again (new values, raw text)
      ├─ compare changed keys
      ├─ parseStringValue(placeholder, new Properties)  // directly fetch from Properties
      └─ BeanWrapper.setPropertyValue(...)              // write back to field

Critically, there is no convertProperties call . parseStringValue reads directly from the Properties object, which still contains xxxx_encrypted, so the field gets written as ciphertext.

Solution

Whether hot update decrypts depends not on overriding convertPropertyValue but on whether the Properties passed to parseStringValue are already decrypted.

Both startup and hot update paths converge at mergeProperties. Therefore, after merging, proactively invoke convertProperties:

@Override
protected Properties mergeProperties() throws IOException {
    Properties properties = super.mergeProperties();
    convertProperties(properties);
    return properties;
}

Now startup and hot updates share the same decrypted Properties. convertPropertyValue still only handles "see _encrypted then decrypt", its responsibility unchanged.

Disconf's own mergeProperties caches the result in lastMergedProperties. We call convertProperties right after super.mergeProperties(), so the cache also holds plaintext. Next comparison of old vs new values compares decrypted content, avoiding false "no change" detection when ciphertext changes to ciphertext.

At startup, convertProperties actually runs twice: once in our mergeProperties, once in Spring's postProcessBeanFactory. This is harmless because decrypted values lack the _encrypted suffix, so the second pass returns them unchanged.

Two Paths, One Diagram

Diagram showing startup and hot update paths converging at mergeProperties
Diagram showing startup and hot update paths converging at mergeProperties

The reason for enhancing mergeProperties in one sentence: move decryption to the point right after Properties are merged , so both startup and hot updates share the already-decrypted Properties.

Core Knowledge Points

1. Spring Provides a "Modify Value" Hook, But Only Guarantees Startup

PropertyResourceConfigurer

roughly implements:

protected void convertProperties(Properties props) {
    Enumeration<?> names = props.propertyNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String value = props.getProperty(name);
        String converted = convertProperty(name, value);
        if (!ObjectUtils.nullSafeEquals(value, converted)) {
            props.setProperty(name, converted);
        }
    }
}

protected String convertPropertyValue(String originalValue) {
    return originalValue; // default does nothing
}

This extension point is for encryption, desensitization, uniform trimming. Jasypt's EncryptablePropertyPlaceholderConfigurer uses the same path. Prerequisite: the caller must go through postProcessBeanFactory . Disconf's hot update takes a separate path, so this hook is not invoked.

2. Disconf Hot Update Is "Direct Object Mutation", Not "Re-run Spring Injection"

At startup, @Value relies on BeanFactory post-processing. During hot update, beans are already in the container; Disconf uses BeanWrapper.setPropertyValue to modify fields by property name.

Thus, hot update decryption depends not on overriding convertPropertyValue but on whether the Properties fed to parseStringValue are already decrypted.

3. Suffix Marking Ciphertext Is Better Than Key Naming

No ENC(...) wrapping, no parallel xxx.encrypted=true key; simply append _encrypted to the value.

Benefits:

In Disconf console, immediately visible which values are ciphertext.

Plaintext and ciphertext can coexist in the same properties file. @Value("${volc.ai.apiKey}") requires no change.

Decrypted values lack the suffix, so convertPropertyValue is idempotent even if called twice.

Trade-off: the convention must be enforced. Plaintext must not accidentally receive _encrypted suffix, otherwise it will be treated as ciphertext and fail decryption.

4. mergeProperties Is the Convergence Point of Both Paths

Comparison of the two paths:

Startup : called by PropertyResourceConfigurer.postProcessBeanFactory; convertProperties is called afterwards by Spring.

Hot Update : called by ReloadingPropertyPlaceholderConfigurer.propertiesReloaded; convertProperties is not called.

To achieve consistent behavior, place decryption at the convergence point. Only overriding convertPropertyValue covers only the first row.

5. Managed Files and Annotation Injection Are Paired

The project uses Disconf in two ways:

XML-managed properties/yml, parsed by PlaceholderConfigurer, then injected via @Value. @DisconfFile style Java config classes.

This decryption hooks into PlaceholderConfigurer, covering the first pattern. Secrets using managed files + @Value are auto-decrypted. If config classes read file content directly, that's a separate path not passing through this Configurer.

Usage Notes

Don't over-encrypt. Switches, whitelists, URLs don't need encryption; it adds debugging cost. Only encrypt AK, SK, tokens, keys.

Test hot updates specifically. Restart-only validation misses the bug. Change an encrypted value in Disconf, verify bean field is plaintext and downstream calls succeed. Avoid logging decrypted secrets.

Let decryption failures surface. Don't swallow exceptions and return original ciphertext. Better to fail startup or hot update than to propagate a bad key to third parties.

Never store the decryption key in Disconf plaintext. Putting the key in Disconf defeats the purpose. Use KMS or machine-side controlled configuration.

The suffix is a contract. The encryption tool's output must end with _encrypted, consistent with the API response encryption marker, aiding operations and debugging.

Summary

Replace Disconf's ReloadingPropertyPlaceholderConfigurer with a decrypting subclass; business @Value unchanged. convertPropertyValue handles "see _encrypted then decrypt", solving startup.

In mergeProperties, proactively call convertProperties, solving hot update's bypass of Spring's conversion hook.

It looks like only a dozen extra lines. The real value is distinguishing the two paths: startup uses Spring's convertProperties, hot update uses Disconf's mergeProperties + BeanWrapper. Hooking the wrong place means restarts always work, but config changes write ciphertext into memory.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Configuration ManagementSpringencryptionhot updateKMSdecryptionDisconfPropertyPlaceholderConfigurer
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.