Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BotSharp.Abstraction.Options;
using System.Security.Cryptography;
using System.Text.Json;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -186,4 +187,25 @@ public static string ConvertToString<T>(this T? value, JsonSerializerOptions? js
var str = JsonSerializer.Serialize(value, jsonOptions);
return str;
}

/// <summary>
/// Get MD5 hash of a string
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string GetMd5Hash(this string text)
{
using MD5 md5 = MD5.Create();
byte[] inputBytes = Encoding.UTF8.GetBytes(text);
byte[] hashBytes = md5.ComputeHash(inputBytes);
Comment on lines +196 to +200
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Action required

1. getmd5hash lacks null guard 📘 Rule violation ⛯ Reliability

The new GetMd5Hash(this string text) method does not guard against null/empty input, so
Encoding.UTF8.GetBytes(text) can throw at call sites. This violates the requirement to add
explicit null/empty guards at boundary-facing utility/provider methods and return a safe fallback.
Agent Prompt
## Issue description
`GetMd5Hash(this string text)` does not validate `text` for null/empty, so it can throw at runtime (e.g., `Encoding.UTF8.GetBytes(text)` with `text == null`).

## Issue Context
Extension methods can be invoked with a null receiver; this helper should defensively return a safe fallback (or `null` if signature is changed) per the compliance requirement.

## Fix Focus Areas
- src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs[196-210]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


// Convert byte array to a 32-character hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2")); // "x2" for lowercase hex
}

return sb.ToString();
}
}
Loading