Skip to content

Commit 6d6331b

Browse files
committed
Add security configuration and validation features
- Introduced SecurityConfigurationException to handle invalid security configurations. - Added SecurityProfile enum to define predefined security profiles for different deployment scenarios. - Implemented state validator registration methods in SecurityServiceExtensions, including support for function-based validators and composite validators. - Enhanced TabSync middleware to fail fast on insecure configurations. - Added FailFastOnInsecureConfiguration option to TabSyncOptions to throw exceptions on misconfigurations. - Created comprehensive unit tests for secure store features, including security profile detection, state validator registration, and exception handling.
1 parent e9ffe83 commit 6d6331b

14 files changed

Lines changed: 2194 additions & 191 deletions

README.md

Lines changed: 273 additions & 121 deletions
Large diffs are not rendered by default.

docs-site/api-reference.html

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,29 @@ <h2 id="registration">Registration Methods</h2>
335335
<p>Methods to register stores in your dependency injection container.</p>
336336

337337
<div class="api-section">
338-
<h4><code>AddStoreWithUtilities</code> (Recommended)</h4>
338+
<h4><code>AddSecureStore</code> (Recommended for Production)</h4>
339+
<p>Automatic security configuration based on environment with all features enabled:</p>
340+
<div class="code-block">
341+
<pre><code class="language-csharp">builder.Services.AddSecureStore(
342+
new AppState(),
343+
"App",
344+
opts =>
345+
{
346+
opts.PersistenceKey = "app-state"; // LocalStorage
347+
opts.EnableTabSync = true; // Cross-tab sync
348+
opts.EnableHistory = true; // Undo/redo
349+
});</code></pre>
350+
</div>
351+
<p>Security profiles applied automatically:</p>
352+
<ul>
353+
<li><code>Development</code>: DevTools enabled, permissive validation</li>
354+
<li><code>Production</code>: No DevTools, message signing enabled, validation warnings</li>
355+
<li><code>Strict</code>: All Production features + throws on any security warning</li>
356+
</ul>
357+
</div>
358+
359+
<div class="api-section">
360+
<h4><code>AddStoreWithUtilities</code></h4>
339361
<p>Registers a store with all utility services (debounce, throttle, cache, async executor) in one call.</p>
340362
<div class="code-block">
341363
<pre><code class="language-csharp">builder.Services.AddStoreWithUtilities(
@@ -376,6 +398,37 @@ <h4><code>AddTransientStore</code> / <code>AddTransientStoreWithUtilities</code>
376398
(store, sp) => store.WithDefaults(sp, "Temp"));</code></pre>
377399
</div>
378400
</div>
401+
402+
<h3>Security Registration Methods</h3>
403+
404+
<div class="api-section">
405+
<h4><code>AddStateValidator&lt;TState, TValidator&gt;</code></h4>
406+
<p>Registers a state validator class for validation during persistence and sync operations.</p>
407+
<div class="code-block">
408+
<pre><code class="language-csharp">builder.Services.AddStateValidator&lt;AppState, AppStateValidator&gt;();</code></pre>
409+
</div>
410+
</div>
411+
412+
<div class="api-section">
413+
<h4><code>AddStateValidator&lt;TState&gt;</code> (Functional)</h4>
414+
<p>Registers a state validator using an inline function.</p>
415+
<div class="code-block">
416+
<pre><code class="language-csharp">builder.Services.AddStateValidator&lt;AppState&gt;(state =>
417+
{
418+
var errors = new List&lt;string&gt;();
419+
if (state.Count &lt; 0) errors.Add("Count cannot be negative");
420+
return errors;
421+
});</code></pre>
422+
</div>
423+
</div>
424+
425+
<div class="api-section">
426+
<h4><code>AddStateValidatorsFromAssembly</code></h4>
427+
<p>Auto-discovers and registers all <code>IStateValidator&lt;T&gt;</code> implementations from an assembly.</p>
428+
<div class="code-block">
429+
<pre><code class="language-csharp">builder.Services.AddStateValidatorsFromAssembly(typeof(Program).Assembly);</code></pre>
430+
</div>
431+
</div>
379432
</section>
380433

381434
<!-- StoreBuilder Configuration -->
@@ -804,6 +857,10 @@ <h2 id="quick-reference">Quick Reference</h2>
804857
</tr>
805858
</thead>
806859
<tbody>
860+
<tr>
861+
<td><code>AddSecureStore()</code></td>
862+
<td>Secure store registration with auto-config</td>
863+
</tr>
807864
<tr>
808865
<td><code>StoreComponent&lt;T&gt;</code></td>
809866
<td>Base component with auto-subscription</td>

docs-site/getting-started.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,32 @@ <h2>Installation</h2>
134134
<!-- Requirements -->
135135
<section class="section">
136136
<h2>Requirements</h2>
137+
<h3>Supported Platforms</h3>
138+
<table class="table">
139+
<thead>
140+
<tr>
141+
<th>.NET Version</th>
142+
<th>Status</th>
143+
</tr>
144+
</thead>
145+
<tbody>
146+
<tr>
147+
<td>.NET 8.0</td>
148+
<td>Fully Supported</td>
149+
</tr>
150+
<tr>
151+
<td>.NET 9.0</td>
152+
<td>Fully Supported</td>
153+
</tr>
154+
<tr>
155+
<td>.NET 10.0</td>
156+
<td>Fully Supported</td>
157+
</tr>
158+
</tbody>
159+
</table>
137160
<div class="alert alert-info">
138161
<div class="alert-title">Prerequisites</div>
139162
<ul style="margin: 0.5rem 0 0 1.5rem;">
140-
<li>.NET 8.0 or higher</li>
141163
<li>Blazor Server, WebAssembly, or Blazor Web App</li>
142164
<li>Package size: Only 38 KB gzipped (less than 0.1% of your app)</li>
143165
</ul>

0 commit comments

Comments
 (0)