Skip to content

API Reference parrot_formdesigner.services.csrf

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.csrf

View source

CSRF token utilities for the remote events endpoint — FEAT-188.

Issues and validates per-session per-form CSRF tokens using an in-process store with a soft TTL of 1 hour.

MVP limitations:

  • In-process dictionary store — tokens are NOT shared across multiple worker processes (e.g., gunicorn with multiple workers). For production deployments with multi-process servers, replace _STORE with a shared backend such as Redis. This is intentional for the MVP; production hardening is a follow-up tracked in the spec §3 Module 6 notes.

Function issue_form_csrf_token

Issue a CSRF token for the given session / form pair.

The token is stored in-process with a TTL of :data:_TTL_SECONDS. Any previously issued token for the same (session_id, form_id) is replaced.

issue_form_csrf_token(session_id: str, form_id: str) -> str

Parameter Type Default Description
session_id str Session identifier extracted from the navigator-auth session cookie.
form_id str Form identifier from the URL path.

Returns: str — A URL-safe 32-byte random token string.

Function validate_form_csrf_token

Validate a CSRF token against the in-process store.

Performs a constant-time comparison to prevent timing attacks. Expired entries are pruned on access.

validate_form_csrf_token(session_id: str, form_id: str, token: str) -> bool

Parameter Type Default Description
session_id str Session identifier.
form_id str Form identifier.
token str Token string from the X-CSRF-Token / X-Form-CSRF-Token request header.

Returns: bool — True if the token matches and has not expired; False otherwise.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally