Search code examples
restsalesforcesalesforce-lightning

Salesforce REST API how to avoid leaking sensitive data in query parameter


I'm trying to do query using REST API, and ran into the following problem:

Using GET request on the query endpoint exposes the entire query string, which may contain sensitive data such as SSN, phone number, etc...

https://[instance-url].my.salesforce.com/services/data/v48.0/query/?q=SELECT Id FROM Contact WHERE SSN__c = '123456789'

How can I do such a query using rest api securely? IS there an equivalent request I can make using at least POST request with post body being the query? since that part is encrypted over https.

Thank you for help


Solution

  • AFAIK, salesforce only provides a GET method for executing SOQL queries. One can write their own REST endpoint in their org that accepts a query in body and execute it, but thats a waste of time in my opinion.

    Query string parameters are secured over https. Its a common misconception, where people think whole url is open in plain text in transmission. When a request is made to an https url, first it establishes a Secure Tunnel to [instance-url].my.salesforce.com then transmits the rest of the url and any other data over the secure tunnel.

    If you're worried about some man in the middle attack sniffing out the SSN from your query string, don't. One downside is, if you are accessing this url from a browser instead of a programmatic call, then there is a chance for browser to stored/cache for history or auto complete, then it won't be so good.

    But I doubt if you would be able to do this via browser, as salesforce requires a bearer token set in Authorization header and there is no easy way that I know of to set headers while typing the url in the browser or clicking a link.

    To know more about how query string is secure over https please refer to this stackoverflow question