isCsrfBlocked (lib/csrf.ts)

tapflow · packages/relay/src/lib/csrf.ts · typescript · MIT
auth

Module exposing: isCsrfBlocked, isLoopbackHost

// Source: https://github.com/jo-duchan/tapflow | License: MIT | Copyright 2026 tapflow contributors
// Provided via justclaw.it.com; keep this notice with the code.
import type http from 'http'

// #5 — CSRF 경량 가드.
// 상태 변경 API가 `SameSite=Lax` 쿠키에만 의존하면 일부 cross-site 요청이 통과할 수 있다.
// 쿠키로 인증된 상태 변경 요청은 Origin이 same-origin(Host 일치)이거나 신뢰 allowlist에 있을 때만
// 허용하고, 그 외 cross-origin은 차단한다. 브라우저는 상태 변경 요청에 Origin을 강제로 붙이므로
// 대시보드(same-origin)는 그대로 통과하고, 공격자 origin은 막힌다.
// 면제: 안전 메서드(GET/HEAD/OPTIONS), PAT 인증(Authorization — 쿠키 자동 전송이 아님),
//       쿠키 없는 요청(미인증/login/init), Origin 없는 요청(비-브라우저; 브라우저는 cross-site에 Origin을 생략하지 못한다).
const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS'])

// Loopback origins are the local dev machine (e.g. Vite :3001 proxying to the relay :4000), never a
// rem

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key