Security policies and credential management
ExecKernel lets your application restrict session inputs and navigation, sign session state, and choose how presentation data is prepared. Those controls act at different points. A context policy can reject an unexpected field before a rule sees it; a credential provider supplies a secret to a server-side component; a presentation sanitizer changes selected payload fields before your application renders them.
A useful configuration starts by deciding which component owns each decision. Your application still identifies the person making a request and decides which sessions, graphs and actions they may access. We return here to the boundary explained in Application responsibilities: the engine evaluates a graph against supplied state; your application supplies trustworthy inputs and controls access to the resulting operation.
Put the control at the boundary it protects
Section titled “Put the control at the boundary it protects”| Boundary | What ExecKernel provides | What your application must decide |
|---|---|---|
| Request → session operation | Graph validation, context validation and runtime policies for languages, edges, history depth, state size and transition spacing. | Which graph and session the caller may use, and which context values the caller may supply. |
| Engine → custom code | A registered custom_rule handler can run through a sandbox driver. The loader can restrict admitted handler names. |
Which code and plugins are trusted, and which driver is suitable. A plugin’s own rule implementation is not automatically wrapped by that driver. |
| Engine → response or export | A presentation sanitizer hook and separate serialization contracts. | Which fields belong in a public response, stored record, exported definition or diagnostic entry. |
| Application → external service | Webhook dispatch/signature contracts and credential-provider interfaces. | Approved destinations, the credential for each component, and how secrets reach the process that uses them. |
These are separate controls. For example, allowing a context key called approved does not establish that the caller is entitled to approve anything. Your application must derive or authorize that value before supplying it.
Configure the runtime policy
Section titled “Configure the runtime policy”FlowSecurityPolicy groups optional restrictions applied by the engine. Without a supplied policy, its open configuration adds none of these restrictions; ordinary graph, context and runtime validation still applies.
| Setting | Effect and practical consequence |
|---|---|
allowedLangs |
Restricts requested languages alongside the graph’s own list. Both lists must permit a request. An empty policy list adds no language restriction. |
forbiddenEdges |
Rejects the listed edge IDs and reports them as blocked in the view. This is a fixed list on that engine configuration, not a user-role lookup. |
maxDepth |
Stops further navigation when the number of edges retained in session history reaches the limit. It is not a request-size limit or a count of all transitions ever made after history has been compacted. |
maxSessionStateSize |
Limits the byte length of the serialized session state, including context and history. It is separate from the presentation payload’s size budget. |
transitionRateLimit |
Requires spacing from lastTransitionAt. TransitionRateLimit(5, 60) requires at least 12 seconds between transitions; it does not count five requests in a shared sliding window. |
contextPolicy |
Applies a ContextValidationPolicy to session context and candidate updates: allowed keys, optional key pattern, array acceptance and depth. It does not define business validation for every value. |
For a concrete example, a document-review application accepts a document reference and offers two routes. Edge 101 opens a preview at terminal 20; edge 102 publishes directly at terminal 30. The application disables direct publication in this integration.
The policy below admits only documentRef in context, keeps English and Spanish presentation available, and bounds retained history and serialized state. ContextValidationPolicy rejects arrays by default; the reference is a string.
use ExecKernel\Domain\Security\FlowSecurityPolicy;use ExecKernel\Domain\Session\ContextValidationPolicy;
$policy = new FlowSecurityPolicy( allowedLangs: ['en', 'es'], forbiddenEdges: [102], maxDepth: 20, maxSessionStateSize: 8192, contextPolicy: new ContextValidationPolicy( keyWhitelist: ['documentRef'], ),);Pass this object as securityPolicy when composing the engine with ExecKernelFactory. The engine revalidates the relevant state and candidate values at its operation boundaries; creating a Context earlier without this policy does not bypass the engine’s configured restrictions.
In the complete example below, an attempted update containing accessToken is rejected with EK-SEC-CTX-001. The session keeps its previous context. The engine also marks edge 102 as blocked, so your application can explain the unavailable route before the person attempts it.
Resolve credentials in application configuration
Section titled “Resolve credentials in application configuration”A credential provider retrieves a string by a logical key. EnvCredentialProvider uses that key as an environment-variable name. InMemoryCredentialProvider keeps a configured snapshot of name/value pairs; it is useful when your application’s existing configuration or secret service has already obtained the values.
Neither provider automatically configures HTTP clients, webhooks or the API deployment. Your application calls get() and passes the result to the component that needs it.
| Credential | Component that uses it | Appropriate location and wiring |
|---|---|---|
| API deployment token | The API’s DeploymentAccessMiddleware checks the incoming Bearer token; your backend’s API client supplies it. |
The deployment reads the file named by EXECKERNEL_API_TOKEN_FILE, defaulting to /run/secrets/api_token. Keep the matching client credential in backend configuration. |
| Webhook signing secret | The HTTP dispatcher signs the exact body; the receiving application verifies it. | Resolve it on the server for an approved destination. Keep it separate from the notification body and from public graph definitions. |
| External-service credential | Your application’s service client or trusted adapter. | Inject it into that client from your application’s configuration. Do not copy it into session context so a rule can make a remote request. |
| Session-integrity key | HmacSessionIntegrity or the session store’s signer. |
Supply it to the signing/verifying components. Keep the key outside session data, exported snapshots and public responses. |
The deployment token grants access to the API service; it does not identify a user or enforce session ownership. API configuration, access and rate limiting develops that service boundary.
Here is the credential part of the document-review integration:
use ExecKernel\Infrastructure\Security\EnvCredentialProvider;use ExecKernel\Infrastructure\Security\HmacSessionIntegrity;
$credentials = new EnvCredentialProvider();$integrity = new HmacSessionIntegrity( $credentials->get('APP_SESSION_SIGNING_KEY'),);APP_SESSION_SIGNING_KEY is an environment-variable name chosen by this application. It is not a new built-in ExecKernel setting. The value comes from the process environment and is never placed in the graph or context.
A missing or empty value causes CredentialNotFoundException with the generic message Credential unavailable.. Treat that as a configuration failure, rather than continuing with an empty credential. The in-memory provider hides values from its normal debug representation and refuses serialization, but get() deliberately returns the secret: code that receives it can still log or expose it.
The signature mechanism is the one introduced in Serialization and session integrity: a verifier checks that the signed state has not changed. It does not encrypt that state. Processes that verify the same records need the appropriate key; replacing the single configured key does not provide automatic verification with an older key.
Keep webhook secrets out of public definitions
Section titled “Keep webhook secrets out of public definitions”We reuse the dispatcher role from Configuring webhooks: the runtime listener prepares an event and passes a subscription plus its payload to a WebhookDispatcherInterface. The subscription identifies delivery configuration; the payload contains event data.
The subscription’s optional secret is a literal secret value. ExecKernel does not expand environment references or resolve a secret_ref field there. If your application injects a value before loading a graph, that loaded graph contains the secret. Its configuration must remain private, including any exports or queue records that retain it.
An alternative is to add the value at the delivery boundary. The following dispatch() method belongs to the application’s SigningWebhookDispatcher adapter in the downloadable example. Its constructor receives a real downstream dispatcher, a CredentialProviderInterface, and a trusted map from exact destination URLs to credential names.
public function dispatch(array $webhookConfig, array $payload): void{ $url = $webhookConfig['url'] ?? null; $key = is_string($url) ? ($this->credentialKeysByUrl[$url] ?? null) : null; if ($key === null) { throw new WebhookDispatchException('Webhook destination is not configured.'); }
$webhookConfig['secret'] = $this->credentials->get($key); $this->next->dispatch($webhookConfig, $payload);}The adapter first checks the destination, then resolves the credential and passes a private configuration copy downstream. The payload is unchanged. The graph supplies neither a secret value nor the name of an arbitrary environment variable to read.
For one approved receiver, the application composes that adapter as follows. $httpDispatcher is the configured ResilientWebhookDispatcher developed in Webhook delivery, retries and queues, which handles the actual HTTP request.
$dispatcher = new SigningWebhookDispatcher( $httpDispatcher, $credentials, ['https://receiver.example.test/events' => 'APP_WEBHOOK_SECRET'],);This exact-URL map is application code, not a built-in network policy. ExecKernel validates webhook URL structure, including the HTTP/HTTPS scheme and the absence of user information and fragments; that validation is not a destination allowlist. Your application controls the map and the network policy used by the delivery process.
security-webhook-signing.php contains the complete adapter and dispatcher composition. Its inspection transport makes no HTTP request: it verifies the generated signature locally and prints this summary for a synthetic event. The second dispatch uses an unconfigured URL.
{ "destination": "https://receiver.example.test/events", "signature_valid": true, "body_fields": [ "event", "context", "event_id", "delivery_id" ], "credential_in_body": false}{"destination_rejected":true}The result shows that this dispatch signed the body without putting its signing key in that body. It does not make arbitrary event data private. In particular, runtime webhook payloads include session or candidate context: keep credentials out of that context from the start. If you place this credential adapter before a queue adapter, its queued configuration also becomes secret-bearing; resolve credentials at the final sender when you need the queue record to remain free of secret values.
Prepare presentation data for its actual destination
Section titled “Prepare presentation data for its actual destination”PayloadSanitizerInterface lets your application transform titles, subtitles, descriptions and edge-label arrays while PayloadBuilder constructs the presentation payload. The default NoopPayloadSanitizer returns them unchanged.
The document-review example supplies an application class named HtmlTextSanitizer. It encodes presentation strings for an HTML-text destination. Its title method is:
public function title(string $value): string{ return htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');}Its nullable subtitle and description methods apply the same transformation, and its labels() method applies it to each label’s text and description. The complete implementation is in the download below. This choice suits the stated HTML-text destination; if your view already uses an escaping template or textContent, keep the encoding responsibility in one place to avoid displaying escaped entities literally.
The factory connects the policy, integrity signer and presentation adapter:
use ExecKernel\Infrastructure\Engine\ExecKernelFactory;
$engine = (new ExecKernelFactory())->build( securityPolicy: $policy, sessionIntegrity: $integrity, payloadSanitizer: new HtmlTextSanitizer(),);The hook does not receive node extras, terminal output URLs/content, session context, logs or graph exports. The label array does include label extras, so a custom labels() implementation can inspect them; the example leaves them unchanged. Neither this hook nor HTML encoding is a general secret-redaction policy. Your application must select public fields and validate output destinations separately.
Check the configured behavior
Section titled “Check the configured behavior”security-policy.php contains the complete review graph, provider, policy, signer, presentation adapter and rejected-update example. Both downloads assume your existing application’s vendor/autoload.php beside the PHP file. Supply APP_SESSION_SIGNING_KEY or APP_WEBHOOK_SECRET through your local configuration, according to the example you run.
php security-policy.php enphp security-webhook-signing.phpThe policy example produces:
{ "title": "Review <draft> & approve", "label": "Open <preview>", "extras": { "category": "report" }, "blocked_edge": { "id": 102, "availability": "blocked" }, "rejected_input": "EK-SEC-CTX-001", "state_changed": false}Your application can present the prepared title and label, explain why direct publication is unavailable, and keep the previous state after the invalid update. The unchanged extras also shows the scope of the presentation hook: data outside its methods needs an explicit application decision before exposure.
Apply that same decision at diagnostic and export boundaries. Return the fields needed by the screen, record the identifiers needed to investigate an operation, and keep secret-bearing configuration out of those records. Logging and audit trails and Tracing and error telemetry describe their own data-selection and sanitization paths. Rule sandboxing and isolation boundaries explains which execution controls protect a custom handler.