fix(inbound,security): bound the sync prefix of inbound scripts by the method timeout; persist a role refresh done on a passive request (INB-1, SEC-1, WP7 task 7.6)
This commit is contained in:
@@ -625,7 +625,15 @@ public class InboundScriptExecutor
|
||||
_scriptHandlers[method.Name] = cached; // last-write-wins; concurrent first-callers race benignly
|
||||
}
|
||||
|
||||
handlerTask = cached.Handler(context);
|
||||
// Start the handler OFF the request thread (INB-1). Script.RunAsync runs the script
|
||||
// synchronously up to its first incomplete await, so invoking the handler inline would
|
||||
// hold the request thread with no deadline for any script that does CPU work or a
|
||||
// blocking call before its first await (TimeoutSeconds and client disconnect both
|
||||
// ignored, no TIMEOUT, abandoned-execution count stuck at 0). Running it on the pool
|
||||
// lets WaitAsync bound the WHOLE run; a non-cooperative script is then abandoned and
|
||||
// counted exactly like one that blocks after an await.
|
||||
var handler = cached.Handler;
|
||||
handlerTask = Task.Run(() => handler(context), cts.Token);
|
||||
var result = await handlerTask.WaitAsync(cts.Token);
|
||||
|
||||
var resultJson = result != null
|
||||
|
||||
@@ -255,7 +255,7 @@ public static class ServiceCollectionExtensions
|
||||
/// asks it for a decision, and applies it to the cookie context:
|
||||
/// <list type="bullet">
|
||||
/// <item><see cref="SessionValidationAction.Reject"/> → <see cref="CookieValidatePrincipalContext.RejectPrincipal"/> + sign out (idle timeout, the directory reports the user gone/disabled/ambiguous/group-less — ScadaBridge#46, or the user's groups now map to no role — ScadaBridge#144).</item>
|
||||
/// <item><see cref="SessionValidationAction.Replace"/> → <see cref="CookieValidatePrincipalContext.ReplacePrincipal"/> + renewal only for non-passive requests (role mapping refreshed).</item>
|
||||
/// <item><see cref="SessionValidationAction.Replace"/> → <see cref="CookieValidatePrincipalContext.ReplacePrincipal"/> + renewal so the refreshed ticket persists, passive requests included (role mapping refreshed).</item>
|
||||
/// <item><see cref="SessionValidationAction.Keep"/> → no-op (no refresh due, or a swallowed refresh fault).</item>
|
||||
/// </list>
|
||||
/// All logic lives in <see cref="CookieSessionValidator.ValidateAsync"/>, which never
|
||||
@@ -302,9 +302,16 @@ public static class ServiceCollectionExtensions
|
||||
|
||||
case SessionValidationAction.Replace when result.Principal is not null:
|
||||
// Role mapping refreshed from stored groups — swap in the rebuilt
|
||||
// principal and re-issue the cookie so the new claims persist.
|
||||
// principal and re-issue the cookie so the new claims (and the advanced
|
||||
// role/group refresh anchors) persist. This holds for passive requests too
|
||||
// (SEC-1): without it the refreshed anchors were thrown away, the next ping
|
||||
// arrived with the old ones and repeated the role re-map / LDAP re-query on every
|
||||
// keep-alive. A passive request's rebuilt principal keeps the OLD LastActivity
|
||||
// claim (CookieSessionValidator, recordActivity: false), so persisting it never
|
||||
// extends the idle window; the sliding renewal of an UNCHANGED principal stays
|
||||
// suppressed for passive requests (OnCheckSlidingExpiration above).
|
||||
context.ReplacePrincipal(result.Principal);
|
||||
context.ShouldRenew = !IsPassiveSessionRequest(context.HttpContext);
|
||||
context.ShouldRenew = true;
|
||||
break;
|
||||
|
||||
case SessionValidationAction.Keep:
|
||||
|
||||
Reference in New Issue
Block a user