Skip to content

Commit f290691

Browse files
committed
Cleanup
1 parent 077174d commit f290691

File tree

2 files changed

+1
-20
lines changed

2 files changed

+1
-20
lines changed

src/BlazorFrame/Services/CspBuilderService.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,14 @@ public CspHeader BuildCspHeader(CspOptions options, IEnumerable<string>? iframeS
4545
{
4646
var directives = new Dictionary<string, List<string>>();
4747

48-
// Handle frame-src and child-src directives
4948
BuildFrameDirectives(directives, options, iframeSources);
5049

51-
// Handle script-src directive
5250
BuildScriptDirectives(directives, options);
5351

54-
// Handle frame-ancestors directive
5552
BuildFrameAncestorsDirectives(directives, options);
5653

57-
// Add custom directives
5854
AddCustomDirectives(directives, options);
5955

60-
// Build the CSP header value
6156
var headerValue = BuildHeaderValue(directives, options);
6257

6358
var headerName = options.ReportOnly
@@ -138,7 +133,6 @@ public CspValidationResult ValidateCspOptions(CspOptions options)
138133
var errors = new List<string>();
139134
var suggestions = new List<string>();
140135

141-
// Check for unsafe practices
142136
if (options.AllowInlineScripts)
143137
{
144138
warnings.Add("Using 'unsafe-inline' in script-src reduces security. Consider using nonces or strict-dynamic.");
@@ -149,13 +143,11 @@ public CspValidationResult ValidateCspOptions(CspOptions options)
149143
warnings.Add("Using 'unsafe-eval' in script-src can enable code injection attacks.");
150144
}
151145

152-
// Check for missing essential directives
153146
if (options.FrameSrc.Count == 0 && options.ChildSrc.Count == 0 && options.AutoDeriveFrameSrc == false)
154147
{
155148
suggestions.Add("Consider adding frame-src or child-src directives to control iframe sources.");
156149
}
157150

158-
// Check for nonce usage
159151
if (!string.IsNullOrEmpty(options.ScriptNonce))
160152
{
161153
if (options.AllowInlineScripts)
@@ -164,7 +156,6 @@ public CspValidationResult ValidateCspOptions(CspOptions options)
164156
}
165157
}
166158

167-
// Check for strict-dynamic usage
168159
if (options.UseStrictDynamic)
169160
{
170161
if (options.AllowInlineScripts || options.AllowEval)
@@ -173,7 +164,6 @@ public CspValidationResult ValidateCspOptions(CspOptions options)
173164
}
174165
}
175166

176-
// Check for report-only mode
177167
if (options.ReportOnly && string.IsNullOrEmpty(options.ReportUri))
178168
{
179169
suggestions.Add("Consider adding a report-uri when using report-only mode to collect violation reports.");
@@ -252,23 +242,20 @@ private void BuildFrameDirectives(Dictionary<string, List<string>> directives, C
252242
{
253243
var frameSources = new List<string>();
254244

255-
// Add explicitly configured frame sources
256245
frameSources.AddRange(options.FrameSrc);
257246

258-
// Auto-derive from iframe sources if enabled
259247
if (options.AutoDeriveFrameSrc && iframeSources != null)
260248
{
261249
var derivedOrigins = ExtractValidOrigins(iframeSources);
262250
frameSources.AddRange(derivedOrigins);
263251
}
264252

265-
// Remove duplicates and add to directives
266253
if (frameSources.Count > 0)
267254
{
268255
directives["frame-src"] = frameSources.Distinct().ToList();
269256
}
270257

271-
// Handle child-src (fallback for older browsers)
258+
// fallback for older browsers
272259
if (options.ChildSrc.Count > 0)
273260
{
274261
directives["child-src"] = options.ChildSrc.Distinct().ToList();
@@ -279,25 +266,21 @@ private void BuildScriptDirectives(Dictionary<string, List<string>> directives,
279266
{
280267
var scriptSources = new List<string>(options.ScriptSrc);
281268

282-
// Add nonce if specified
283269
if (!string.IsNullOrEmpty(options.ScriptNonce))
284270
{
285271
scriptSources.Add($"'nonce-{options.ScriptNonce}'");
286272
}
287273

288-
// Add unsafe-inline if allowed
289274
if (options.AllowInlineScripts)
290275
{
291276
scriptSources.Add(Sources.UnsafeInline);
292277
}
293278

294-
// Add unsafe-eval if allowed
295279
if (options.AllowEval)
296280
{
297281
scriptSources.Add(Sources.UnsafeEval);
298282
}
299283

300-
// Add strict-dynamic if enabled
301284
if (options.UseStrictDynamic)
302285
{
303286
scriptSources.Add(Sources.StrictDynamic);
@@ -348,7 +331,6 @@ private string BuildHeaderValue(Dictionary<string, List<string>> directives, Csp
348331
}
349332
}
350333

351-
// Add report-uri if specified
352334
if (!string.IsNullOrEmpty(options.ReportUri))
353335
{
354336
if (sb.Length > 0)

src/BlazorFrame/Services/MessageValidationService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public IframeMessage ValidateMessage(
4141
$"Message size ({messageJson.Length} bytes) exceeds maximum allowed size ({options.MaxMessageSize} bytes)");
4242
}
4343

44-
// Check for potentially malicious content
4544
if (ContainsSuspiciousContent(messageJson))
4645
{
4746
return CreateInvalidMessage(origin, messageJson, "Message contains potentially malicious content");

0 commit comments

Comments
 (0)