I'm working on a managed package where a requirement, out of our hands, is to authenticate to a SOAP API via WS-Security. I was hoping we'd take the strategy of using Named Credentials. This would require us to use merge fields (as documented here https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_named_credentials_merge_fields.htm). Since the WS-Security XML header is in the HTTP request body, the named credential needs to have the "Allow Merge Fields in HTTP Body" option ticked.
It's occurred to me though, there could be a security risk here. These API calls will contain data mapped by an administrator to send from records in their org. If user were to include the text {!$Credential.Password}
somewhere in a text field of a record, oops, now that password would be substituted somewhere it shouldn't be.
Would it be wisest to sanitize the rest of the request body to avoid this? Any user data would definitely come after the XML header so I could, for example, check if xmlString.countMatches('$Credential') > 2
. And if so, either throw an error or replace it with something safe.
And for that matter, would it be a Security Review concern if our package will only work when the Named Credential "Allow Merge Fields in HTTP Body" is ticked?