veryfront/security

Import

TypeScript
import {  applyCORSHeaders,  applyCORSHeadersSync,  applyCsrfCookie,  applySecurityHeaders,  buildCacheControl,  cors,} from "veryfront/security";

Examples

Apply response security headers

TypeScript
import { applySecurityHeaders, generateNonce } from "veryfront/security"; const response = new Response("Ready");applySecurityHeaders(response.headers, false, generateNonce(), null);

Exports

Components

NameDescriptionSource
BUILD_HELPER_PERMISSIONSBUILD_HELPER - manifest generators, framework source prep. Only needs filesystem + env access.source
CACHE_DURATIONSsource
CommonSchemasLazy-getter object that preserves the CommonSchemas.email call shape. Each access returns the cached Schema<T> (memoized inside defineSchema), so chained calls like CommonSchemas.email.parse(x) work as before.source
CORS_MAX_AGEsource
DEFAULT_CORS_HEADERSsource
DEFAULT_CORS_METHODSsource
DEFAULT_LIMITSFramework-owned request limits.source
INPUT_VALIDATION_FAILEDHTTP request input validation failures (replaces ValidationError)source
PathValidationErrorsource
SECURITY_VIOLATIONPath traversal / secure-fs violations (replaces SecurityError)source
SERVER_PERMISSIONSSERVER - CLI server (dev, production, proxy, MCP, split-mode). Also used by build and test tasks that need equivalent access.source
ValidationPresetssource
WORKFLOW_RUN_PERMISSIONSWORKFLOW_RUN - ProcessRunExecutor (RESTRICTED). Runs user-authored code - no --allow-run, --allow-ffi, or --allow-sys.source

Functions

NameDescriptionSource
applyCORSHeaderssource
applyCORSHeadersSyncApply CORS synchronously. Promise-returning values still fail closed at runtime.source
applyCsrfCookieSet or refresh browser-readable CSRF token and name-advertisement cookies on GET/HEAD responses. Existing tokens stay in place while stale or missing current and sibling advertisements are synchronized.source
applySecurityHeaderssource
buildCacheControlsource
corsCreate CORS middleware.source
corsSimplesource
createResponseBuildersource
createSecureFssource
createValidatedHandlerCreate a validated API handler with bounded body/query validation. Bodies without a schema are preflighted through a clone, leaving the original request body available to the handler after its size is verified.source
createValidationErrorCreate an input validation error. Convenience wrapper around INPUT_VALIDATION_FAILED.create().source
createValidatorsource
generateCsrfTokenGenerate a CSRF token and return value + Set-Cookie header stringsource
generateNoncesource
getSecurityHeadersource
handleCORSPreflightsource
isPreflightRequestsource
isRequestBodyTooLargeErrorsource
isValidSecurityConfigCheck a standalone security configuration against the canonical project configuration schema.source
loadSecurityConfigLoad the project's schema-validated security configuration.source
parseFormDataParse and validate multipart or URL-encoded form data.source
parseJsonBodyParse and validate a JSON request body.source
parseQueryParamsParse and validate query parameters from a bounded request URL.source
readBodyWithLimitsource
sanitizeDataSanitize JSON-like data by HTML-encoding string values and removing keys that can mutate an object's prototype chain.source
sanitizePathForDisplaysource
setCorssource
shouldApplyCORSsource
validateCORSConfigValidate CORS configuration for security issues.source
validateCsrfValidate CSRF token by comparing header and cookiesource
validateLexicalPathValidate lexical path containment without consulting a filesystem.source
validateOriginValidate origin against CORS configuration.source
validateOriginSyncSynchronous origin validation. Promise-returning values still fail closed at runtime.source
validatePathAdmit a path against the physical semantics of a runtime filesystem.source
validatePathSyncValidate lexical path containment without consulting a filesystem.source
validateRequestLimitssource
wrapAdapterWithSecuritysource

Classes

NameDescriptionSource
AuthHandlersource
BaseHandlersource
CsrfHandlersource
ResponseBuildersource
SecureFssource
SecurityConfigLoadersource

Types

NameDescriptionSource
ApplicationIdentityAuthenticated application user context exposed during a request.source
AuthClaimPrimitiveA scalar value retained from authenticated provider claims.source
AuthClaimValueA JSON-safe value retained from authenticated provider claims.source
AuthConfigApplication authentication. Runtime validation requires exactly one configured mode.source
BasicAuthConfigsource
BearerAuthConfigsource
CacheStrategysource
CORSConfigsource
CORSHeaderOptionssource
CORSOptionsCORS policy accepted by asynchronous middleware and preflight APIs.source
CORSPreflightOptionssource
CORSValidationResultsource
CSPDirectivessource
CsrfConfigsource
CsrfTokenOptionssource
HandlerHelperssource
LexicalPathValidationOptionsOptions for lexical containment checks that never inspect a filesystem.source
OidcAuthConfigOpenID Connect authentication configured through environment-backed credentials.source
OriginValidatorsource
ParseFormOptionssource
ParseJsonOptionssource
ParseQueryOptionssource
PathValidationPolicyOptionsFilesystem-independent policy fields shared by physical path presets.source
RequestLimitssource
ResponseBuilderConfigsource
SecureFsConfigsource
SecurityConfigsource
SecurityContextsource
SecurityEventsource
SerializedApplicationIdentitySerializable authenticated application user context.source
SerializedAuthClaimsAn immutable snapshot of authenticated provider claims.source
SyncCORSConfigCORS policy accepted by synchronous response-building APIs.source
SyncCORSHeaderOptionsHeader options accepted by synchronous CORS response helpers.source
SyncOriginValidatorsource
TrustedProxyAuthConfigIdentity headers accepted from explicitly trusted reverse-proxy peers.source
ValidatedDatasource
ValidatedHandlerConfigConfiguration for createValidatedHandler().source
ValidatedHandlerFunctionHandler signature that receives validated request data.source
ValidationLevelsource
ValidationOptionsOptions for physical filesystem admission.source
ValidationResultsource