Skip to content

Commit 7f04fc9

Browse files
committed
Address feedback to make validation more specific. Removed forcing offline mode.
1 parent 0f63f7d commit 7f04fc9

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

pkgs/sdk/server/src/Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ internal Configuration(ConfigurationBuilder builder)
187187
Events = builder._events;
188188
Http = builder._http;
189189
Logging = builder._logging;
190-
Offline = builder._sdkKey == null || builder._offline;
190+
Offline = builder._offline;
191191
SdkKey = builder._sdkKey;
192192
ServiceEndpoints = (builder._serviceEndpointsBuilder ?? Components.ServiceEndpoints()).Build();
193193
StartWaitTime = builder._startWaitTime;

pkgs/sdk/server/src/ConfigurationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public sealed class ConfigurationBuilder
5959
/// </summary>
6060
private void SetSdkKeyIfValid(string sdkKey)
6161
{
62-
if (ValidationUtils.ValidateStringValue(sdkKey) == null)
62+
if (ValidationUtils.ValidateSdkKeyFormat(sdkKey) == null)
6363
{
6464
_sdkKey = sdkKey;
6565
}

pkgs/shared/common/src/Helpers/ValidationUtils.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,33 @@ public static class ValidationUtils
1010
{
1111
private static readonly Regex ValidCharsRegex = new Regex("^[-a-zA-Z0-9._]+\\z");
1212

13+
/// <summary>
14+
/// Validates that a string does not contain invalid characters or exceed the max length of 8192 characters.
15+
/// </summary>
16+
/// <param name="sdkKey">the SDK key to validate.</param>
17+
/// <returns>Null if the input is valid, otherwise an error string describing the issue.</returns>
18+
public static string ValidateSdkKeyFormat(string sdkKey)
19+
{
20+
21+
// For offline mode, we allow a null or empty SDK key and it is not invalid.
22+
if (string.IsNullOrEmpty(sdkKey))
23+
{
24+
return null;
25+
}
26+
27+
if (sdkKey.Length > 8192)
28+
{
29+
return "SDK key cannot be longer than 1024 characters.";
30+
}
31+
32+
if (!ValidCharsRegex.IsMatch(sdkKey))
33+
{
34+
return "SDK key contains invalid characters.";
35+
}
36+
37+
return null;
38+
}
39+
1340
/// <summary>
1441
/// Validates that a string is non-empty, not too longer for our systems, and only contains
1542
/// alphanumeric characters, hyphens, periods, and underscores.

0 commit comments

Comments
 (0)