Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

In here Encrypted fields it says

Data for encrypted fields in the debug log is masked

I have this page

<apex:page standardController="account" extensions="ext" >
<apex:form >
<apex:outputfield value="{!account.password__c}"></apex:outputfield>
</apex:form>

and extension class

public class ext {
apexpages.standardcontroller sc1;
public ext (apexpages.standardcontroller sc)
{
 sc1 = sc;
 account a = (account)sc1.getrecord();
 system.debug(a.password__C);
}
}

when i look at debug log ,i can see

16:16:47.062 (62513108)|SYSTEM_METHOD_ENTRY|[7]|System.debug(ANY) 16:16:47.062 (62533903)|USER_DEBUG|[7]|DEBUG|hijkl

Can see unmasked value is being displayed . (i dont have view encrypteddata permission enabled and my page does display this field masked)

why is this so?

share|improve this question

1 Answer 1

This appears to be a bug of some sort; I was able to replicate it. Generally, the system does protect against encrypted data exposure. Here's some things I tried:

// Execute Anonymous
Account record = [SELECT Id,Name,Encrypted__c FROM account where name = 'testx1234'];
String x = record.Encrypted__c;
System.debug(logginglevel.error, record);
System.debug(logginglevel.error, x);
System.debug(logginglevel.error, record.Encrypted__c);

Output:

13:58:40.030 (30791101)|USER_DEBUG|[3]|ERROR|Account:{Name=TestX1234, Encrypted__c=****, Id=0015000000u5QiWAAU}
13:58:40.030 (30828356)|USER_DEBUG|[4]|ERROR|****
13:58:40.030 (30861310)|USER_DEBUG|[5]|ERROR|****

I then tried the same concept using a controller:

public with sharing class accountCtrl {
    public accountCtrl(ApexPages.StandardController controller) {
        Account record = (Account)controller.getRecord();
        System.debug(LoggingLevel.ERROR, record);
        System.debug(LoggingLevel.ERROR, record.Encrypted__c);
        String x = record.Encrypted__c;
        System.debug(LoggingLevel.ERROR, x);
        Account record2 =[SELECT Id, Name, Encrypted__c FROM Account WHERE Id = :record.Id];
        System.debug(LoggingLevel.ERROR, record2);
        System.debug(LoggingLevel.ERROR, record2.Encrypted__c);
        x = record2.Encrypted__c;
        System.debug(LoggingLevel.ERROR, x);
    }
}

The output here was different:

13:57:37.124 (124467952)|USER_DEBUG|[4]|ERROR|Account:{RecordTypeId=01250000000QNyFAAW, Encrypted__c=****, Id=0015000000u5QiWAAU, IsPersonAccount=false}
13:57:37.124 (124533149)|USER_DEBUG|[5]|ERROR|ABCD
13:57:37.124 (124564371)|USER_DEBUG|[7]|ERROR|ABCD
13:57:37.129 (129214484)|USER_DEBUG|[9]|ERROR|Account:{Name=TestX1234, RecordTypeId=01250000000QNyFAAW, Encrypted__c=****, Id=0015000000u5QiWAAU}
13:57:37.129 (129260562)|USER_DEBUG|[10]|ERROR|ABCD
13:57:37.129 (129290380)|USER_DEBUG|[12]|ERROR|ABCD

The moral of the story is that, depending on the execution context and means of accessing the record, explicitly debugging the field may result in data exposure, but debugging the record itself should obscure the text.


Edit

After more testing, I came up with this code:

// Execute anonymous
Account record = [SELECT Id,Name,Encrypted__c FROM account where name = 'testx1234'];
record.Encrypted__c = 'BCDE';
String x = record.Encrypted__c;
System.debug(logginglevel.error, record);
System.debug(logginglevel.error, x);
System.debug(logginglevel.error, record.Encrypted__c);

Which had the output:

14:04:57.034 (34482749)|USER_DEBUG|[4]|ERROR|Account:{Name=TestX1234, Encrypted__c=****, Id=0015000000u5QiWAAU}
14:04:57.034 (34525409)|USER_DEBUG|[5]|ERROR|BCDE
14:04:57.034 (34575783)|USER_DEBUG|[6]|ERROR|BCDE

It would appear that tainting only occurs at certain points in the lifecycle, and that Visualforce context provides less protection than Execute Anonymous. The only guarantee that I could find is that debugging the record itself always encrypted the text value, but debugging just the field or a copy of the field value often resulted in data exposure.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.