Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #262: Moved from Newtonsoft.Json to System.Text.Json #324

Closed

Conversation

antoineatstariongroup
Copy link
Contributor

@antoineatstariongroup antoineatstariongroup commented Mar 21, 2024

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the COMET-SDK code style guidelines
  • I have provided test coverage for my change (where applicable)

Description

Fix #262

  • Remove all dependencies to Newtonsoft.Json
  • All (de)serializers uses the most low-level Json calls
  • Creation of CDP4DalJsonSerializer that support (de)serialization of any PostOperation class
  • Creation of versionBump script that update all VersionPrefix entries for every csproj files
  • Added Deserialize(string)
  • PostOperation is not abstract anymore

BREAKING CHANGES :

  • Standard CDP4JsonSerializer should NOT be used anymore is case of PostOperation (de)serialization
  • PostOperation, Operation and Operation kind moved to new Namespace: CDP4DalCommon.Protocol.Operations

@antoineatstariongroup
Copy link
Contributor Author

I think that the issue found by SQ should be discarded and non-relevant with the context of the code

public override void Write(Utf8JsonWriter writer, PostOperation value, JsonSerializerOptions options)
{
writer.WriteStartObject();
writer.WriteStartArray("_delete");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing "u8"

{
domainOfExpertise.Name = jObject["name"].ToObject<string>();
if(nameProperty.ValueKind == JsonValueKind.Null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets log at Trace level

<PackageTags>CDP COMET ECSS-E-TM-10-25 JSON</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[BUMP] To CDP4Common 26.6.0
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please restore the README.md

@@ -0,0 +1,20 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure to add some docs somewhere what the purpose is and how to use it

emailAddress.ModifiedOn = jObject["modifiedOn"].ToObject<DateTime>();
if(modifiedOnProperty.ValueKind == JsonValueKind.Null)
{
Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);

Check warning

Code scanning / CodeQL

Exposure of private information Medium

Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.

Copilot Autofix AI about 2 months ago

To fix the problem, we should avoid logging sensitive information directly. Instead, we can log a generic message without including the potentially sensitive emailAddress.Iid. This way, we maintain the logging functionality for debugging purposes without exposing private data.

  • Modify the logging statements to exclude the emailAddress.Iid.
  • Ensure that the log messages still provide useful information for debugging without revealing sensitive data.
Suggested changeset 1
CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
--- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
+++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
@@ -85,3 +85,3 @@
                 {
-                    Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale modifiedOn property of an emailAddress is null");
                 }
@@ -97,3 +97,3 @@
                 {
-                    Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale thingPreference property of an emailAddress is null");
                 }
@@ -109,3 +109,3 @@
                 {
-                    Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale value property of an emailAddress is null");
                 }
@@ -121,3 +121,3 @@
                 {
-                    Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale vcardType property of an emailAddress is null");
                 }
EOF
@@ -85,3 +85,3 @@
{
Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale modifiedOn property of an emailAddress is null");
}
@@ -97,3 +97,3 @@
{
Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale thingPreference property of an emailAddress is null");
}
@@ -109,3 +109,3 @@
{
Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale value property of an emailAddress is null");
}
@@ -121,3 +121,3 @@
{
Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale vcardType property of an emailAddress is null");
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
emailAddress.ThingPreference = jObject["thingPreference"].ToObject<string>();
if(thingPreferenceProperty.ValueKind == JsonValueKind.Null)
{
Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);

Check warning

Code scanning / CodeQL

Exposure of private information Medium

Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that sensitive information is not logged directly. Instead of logging the actual emailAddress.Iid, we can log a masked or sanitized version of it. This way, we can still retain useful logging information for debugging purposes without exposing sensitive data.

The best way to fix this problem is to modify the logging statements to mask the emailAddress.Iid before logging it. We can create a helper method to mask the Iid and use this method in the logging statements.

Suggested changeset 1
CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
--- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
+++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
@@ -45,2 +45,12 @@
         /// <summary>
+        /// Masks the Iid to prevent exposure of sensitive information
+        /// </summary>
+        /// <param name="iid">The Iid to mask</param>
+        /// <returns>The masked Iid</returns>
+        private static string MaskIid(Guid iid)
+        {
+            return iid.ToString().Substring(0, 8) + "****";
+        }
+
+        /// <summary>
         /// Instantiate and deserialize the properties of a <see cref="CDP4Common.DTO.EmailAddress"/>
@@ -85,3 +95,3 @@
                 {
-                    Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", MaskIid(emailAddress.Iid));
                 }
@@ -97,3 +107,3 @@
                 {
-                    Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", MaskIid(emailAddress.Iid));
                 }
@@ -109,3 +119,3 @@
                 {
-                    Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", MaskIid(emailAddress.Iid));
                 }
@@ -121,3 +131,3 @@
                 {
-                    Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", MaskIid(emailAddress.Iid));
                 }
EOF
@@ -45,2 +45,12 @@
/// <summary>
/// Masks the Iid to prevent exposure of sensitive information
/// </summary>
/// <param name="iid">The Iid to mask</param>
/// <returns>The masked Iid</returns>
private static string MaskIid(Guid iid)
{
return iid.ToString().Substring(0, 8) + "****";
}

/// <summary>
/// Instantiate and deserialize the properties of a <see cref="CDP4Common.DTO.EmailAddress"/>
@@ -85,3 +95,3 @@
{
Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", MaskIid(emailAddress.Iid));
}
@@ -97,3 +107,3 @@
{
Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", MaskIid(emailAddress.Iid));
}
@@ -109,3 +119,3 @@
{
Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", MaskIid(emailAddress.Iid));
}
@@ -121,3 +131,3 @@
{
Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", MaskIid(emailAddress.Iid));
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
emailAddress.Value = jObject["value"].ToObject<string>();
if(valueProperty.ValueKind == JsonValueKind.Null)
{
Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);

Check warning

Code scanning / CodeQL

Exposure of private information Medium

Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that private information is not logged directly. Instead, we can log a sanitized or masked version of the Iid to prevent exposure of sensitive data. This can be done by hashing the Iid before logging it, which will allow us to log a consistent identifier without revealing the actual value.

The best way to fix the problem without changing existing functionality is to modify the logging statements to log a hashed version of the Iid. We will use a cryptographic hash function to generate a hash of the Iid and log the hash instead of the raw Iid.

Suggested changeset 1
CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
--- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
+++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
@@ -31,2 +31,4 @@
     using System.Text.Json;
+    using System.Security.Cryptography;
+    using System.Text;
 
@@ -44,2 +46,11 @@
 
+        private static string HashIid(Guid iid)
+        {
+            using (var sha256 = SHA256.Create())
+            {
+                var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(iid.ToString()));
+                return Convert.ToBase64String(hash);
+            }
+        }
+
         /// <summary>
@@ -85,3 +96,3 @@
                 {
-                    Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", HashIid(emailAddress.Iid));
                 }
@@ -97,3 +108,3 @@
                 {
-                    Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", HashIid(emailAddress.Iid));
                 }
@@ -109,3 +120,3 @@
                 {
-                    Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", HashIid(emailAddress.Iid));
                 }
@@ -121,3 +132,3 @@
                 {
-                    Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", HashIid(emailAddress.Iid));
                 }
EOF
@@ -31,2 +31,4 @@
using System.Text.Json;
using System.Security.Cryptography;
using System.Text;

@@ -44,2 +46,11 @@

private static string HashIid(Guid iid)
{
using (var sha256 = SHA256.Create())
{
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(iid.ToString()));
return Convert.ToBase64String(hash);
}
}

/// <summary>
@@ -85,3 +96,3 @@
{
Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", HashIid(emailAddress.Iid));
}
@@ -97,3 +108,3 @@
{
Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", HashIid(emailAddress.Iid));
}
@@ -109,3 +120,3 @@
{
Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", HashIid(emailAddress.Iid));
}
@@ -121,3 +132,3 @@
{
Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", HashIid(emailAddress.Iid));
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
emailAddress.VcardType = jObject["vcardType"].ToObject<VcardEmailAddressKind>();
if(vcardTypeProperty.ValueKind == JsonValueKind.Null)
{
Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);

Check warning

Code scanning / CodeQL

Exposure of private information Medium

Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.
Private data returned by
access to local variable emailAddress
is written to an external location.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that sensitive information is not logged. In this case, we should avoid logging the emailAddress.Iid directly. Instead, we can log a generic message without including the potentially sensitive Iid. This change should be made in the FromJsonObject method of the EmailAddressResolver class.

  • Replace the logging statements that include emailAddress.Iid with generic messages.
  • Ensure that the functionality of the code remains unchanged, except for the logging behavior.
Suggested changeset 1
CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
--- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
+++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs
@@ -85,3 +85,3 @@
                 {
-                    Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale modifiedOn property of the emailAddress is null");
                 }
@@ -97,3 +97,3 @@
                 {
-                    Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale thingPreference property of the emailAddress is null");
                 }
@@ -109,3 +109,3 @@
                 {
-                    Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale value property of the emailAddress is null");
                 }
@@ -121,3 +121,3 @@
                 {
-                    Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);
+                    Logger.Trace("The non-nullabale vcardType property of the emailAddress is null");
                 }
EOF
@@ -85,3 +85,3 @@
{
Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale modifiedOn property of the emailAddress is null");
}
@@ -97,3 +97,3 @@
{
Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale thingPreference property of the emailAddress is null");
}
@@ -109,3 +109,3 @@
{
Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale value property of the emailAddress is null");
}
@@ -121,3 +121,3 @@
{
Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid);
Logger.Trace("The non-nullabale vcardType property of the emailAddress is null");
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
/// Initializes a new <see cref="PostOperationJsonConverter" /> instance.
/// </summary>
/// <param name="ignoreCopyProperty">Asserts that the <see cref="PostOperation.Copy"/> have to be ignored</param>
public PostOperationJsonConverter(bool ignoreCopyProperty = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default should be true, since this is special for COMET and not supported by version 1,0.0 of 10-25

Copy link

telephoneNumber.ModifiedOn = jObject["modifiedOn"].ToObject<DateTime>();
if(modifiedOnProperty.ValueKind == JsonValueKind.Null)
{
Logger.Trace("The non-nullabale modifiedOn property of the telephoneNumber {id} is null", telephoneNumber.Iid);

Check warning

Code scanning / CodeQL

Exposure of private information Medium

Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.

Copilot Autofix AI about 2 months ago

To fix the problem, we should avoid logging sensitive information directly. Instead, we can log a generic message or mask the sensitive parts of the data. In this case, we will replace the logging of telephoneNumber.Iid with a generic message that does not include the potentially sensitive identifier.

  • Replace the logging statement on line 86 with a generic message that does not include telephoneNumber.Iid.
  • Ensure that no sensitive information is logged in other parts of the code.
Suggested changeset 1
CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
--- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
+++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
@@ -85,3 +85,3 @@
                 {
-                    Logger.Trace("The non-nullabale modifiedOn property of the telephoneNumber {id} is null", telephoneNumber.Iid);
+                    Logger.Trace("The non-nullabale modifiedOn property of a telephoneNumber is null");
                 }
@@ -97,3 +97,3 @@
                 {
-                    Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid);
+                    Logger.Trace("The non-nullabale thingPreference property of a telephoneNumber is null");
                 }
@@ -109,3 +109,3 @@
                 {
-                    Logger.Trace("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid);
+                    Logger.Trace("The non-nullabale value property of a telephoneNumber is null");
                 }
EOF
@@ -85,3 +85,3 @@
{
Logger.Trace("The non-nullabale modifiedOn property of the telephoneNumber {id} is null", telephoneNumber.Iid);
Logger.Trace("The non-nullabale modifiedOn property of a telephoneNumber is null");
}
@@ -97,3 +97,3 @@
{
Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid);
Logger.Trace("The non-nullabale thingPreference property of a telephoneNumber is null");
}
@@ -109,3 +109,3 @@
{
Logger.Trace("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid);
Logger.Trace("The non-nullabale value property of a telephoneNumber is null");
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
telephoneNumber.ThingPreference = jObject["thingPreference"].ToObject<string>();
if(thingPreferenceProperty.ValueKind == JsonValueKind.Null)
{
Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid);

Check warning

Code scanning / CodeQL

Exposure of private information Medium

Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that sensitive information is not logged directly. Instead of logging the actual telephoneNumber.Iid, we can log a masked or hashed version of it. This way, the identifier is obfuscated, and the risk of exposing private information is mitigated.

The best way to fix the problem without changing existing functionality is to hash the telephoneNumber.Iid before logging it. We can use a cryptographic hash function to generate a fixed-length hash of the identifier, which can then be safely logged.

We need to make the following changes:

  1. Import the necessary cryptographic library.
  2. Create a method to hash the telephoneNumber.Iid.
  3. Use the hashed value in the log message instead of the plain identifier.
Suggested changeset 1
CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
--- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
+++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
@@ -31,2 +31,4 @@
     using System.Text.Json;
+    using System.Security.Cryptography;
+    using System.Text;
 
@@ -44,2 +46,16 @@
 
+        private static string HashIdentifier(Guid id)
+        {
+            using (SHA256 sha256 = SHA256.Create())
+            {
+                byte[] bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(id.ToString()));
+                StringBuilder builder = new StringBuilder();
+                for (int i = 0; i < bytes.Length; i++)
+                {
+                    builder.Append(bytes[i].ToString("x2"));
+                }
+                return builder.ToString();
+            }
+        }
+
         /// <summary>
@@ -97,3 +113,3 @@
                 {
-                    Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid);
+                    Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", HashIdentifier(telephoneNumber.Iid));
                 }
EOF
@@ -31,2 +31,4 @@
using System.Text.Json;
using System.Security.Cryptography;
using System.Text;

@@ -44,2 +46,16 @@

private static string HashIdentifier(Guid id)
{
using (SHA256 sha256 = SHA256.Create())
{
byte[] bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(id.ToString()));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}

/// <summary>
@@ -97,3 +113,3 @@
{
Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid);
Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", HashIdentifier(telephoneNumber.Iid));
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
telephoneNumber.Value = jObject["value"].ToObject<string>();
if(valueProperty.ValueKind == JsonValueKind.Null)
{
Logger.Trace("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid);

Check warning

Code scanning / CodeQL

Exposure of private information Medium

Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.
Private data returned by
access to local variable telephoneNumber
is written to an external location.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to ensure that sensitive information is not logged. We can achieve this by either removing the logging statement or by masking the sensitive information before logging it. In this case, we will remove the logging statement to prevent any potential exposure of private information.

Suggested changeset 1
CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
--- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
+++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs
@@ -109,3 +109,3 @@
                 {
-                    Logger.Trace("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid);
+                    Logger.Trace("The non-nullabale value property of the telephoneNumber is null");
                 }
EOF
@@ -109,3 +109,3 @@
{
Logger.Trace("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid);
Logger.Trace("The non-nullabale value property of the telephoneNumber is null");
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CodeGenerate] a system.json.text based CDP4JsonSerializer
3 participants