Describe the bug
Description
We have the situation where the same DTO, including properties that are encrypted by NServiceBus.Encryption.MessageProperty, is sent more than once. The first message that is sent has properly encrypted values, however the second message that gets sent has its properties encrypted twice. Which is obviously not expected or wanted.
We're using convention-based encryption rather than the EncryptedString type, by the way.
The code with which we're running into this issue is the following:
if(...)
{
if (compareResult.Contains(CompareResult.Core))
{
//1) We start with modifiedEsbMedewerker having only plaintext values.
await _serviceBusAdapterProxy.PublishMedewerkerCoreUpdated(modifiedEsbMedewerker);
//2) At this point the sensitive string properties on modifiedEsbMedewerker contain encrypted values.
}
}
if (!compareResult.Contains(CompareResult.MedewerkerNummerMissing))
{
//3) If we get here, the encrypted properties get encrypted again before sending the second event.
await _serviceBusAdapterProxy.PublishMedewerkerUpdated(modifiedEsbMedewerker);
}
Expected behavior
At point 2, I would expect all properties on the modifiedEsbMedewerker to still have their plaintext values.
Actual behavior
At point 2, the properties that should be encrypted instead contain their encrypted values, which means that I can't use this DTO further down the line, and that when I want to send it again (at point 3), the encrypted value gets encrypted again before sending (which looks really weird on the receiving side btw, just as if encryption failed or isn't configured properly).
Where this probably goes wrong is at https://github.com/Particular/NServiceBus.Encryption.MessageProperty/blob/master/src/MessageProperty/StringConversions.cs#L12, where the plaintext is overwritten with the encrypted value.
Versions
We're using:
- NServiceBus Version 9.2.8
- NServiceBus.Encryption.MessageProperty Version 5.0.1
Steps to reproduce
Basically as shown above:
- Configure property encryption by convention
- Send
myDto with a property to be encrypted as part of an event
- Send the same
myDto again, the encrypted property is encrypted again before sending.
Relevant log output
Additional Information
Workarounds
We currently create a deep-copy of the DTO that gets passed to the Publish() method, so that one gets changed instead and the original DTO can be used again. From a performance point this isn't optimal however.
Backported To
Describe the bug
Description
We have the situation where the same DTO, including properties that are encrypted by
NServiceBus.Encryption.MessageProperty, is sent more than once. The first message that is sent has properly encrypted values, however the second message that gets sent has its properties encrypted twice. Which is obviously not expected or wanted.We're using convention-based encryption rather than the
EncryptedStringtype, by the way.The code with which we're running into this issue is the following:
Expected behavior
At point 2, I would expect all properties on the modifiedEsbMedewerker to still have their plaintext values.
Actual behavior
At point 2, the properties that should be encrypted instead contain their encrypted values, which means that I can't use this DTO further down the line, and that when I want to send it again (at point 3), the encrypted value gets encrypted again before sending (which looks really weird on the receiving side btw, just as if encryption failed or isn't configured properly).
Where this probably goes wrong is at https://github.com/Particular/NServiceBus.Encryption.MessageProperty/blob/master/src/MessageProperty/StringConversions.cs#L12, where the plaintext is overwritten with the encrypted value.
Versions
We're using:
Steps to reproduce
Basically as shown above:
myDtowith a property to be encrypted as part of an eventmyDtoagain, the encrypted property is encrypted again before sending.Relevant log output
Additional Information
Workarounds
We currently create a deep-copy of the DTO that gets passed to the Publish() method, so that one gets changed instead and the original DTO can be used again. From a performance point this isn't optimal however.
Backported To