Skip to content

Refactor strict-mode #34

Closed
Closed

Description

@nielsenko

Current Implementation

The strict-mode currently operates at a global level through the strictHeaders flag in the server configuration. This affects how all headers are validated:

Current Behavior

  • When strictHeaders: true:
    • Invalid headers trigger a BadRequestException
    • Empty header values are rejected
    • Malformed headers (e.g., invalid max-age in Strict-Transport-Security) cause request failures
  • When strictHeaders: false:
    • Invalid headers return null
    • Validation errors are suppressed
    • Applications must handle potentially invalid headers

Problems with Current Approach

  1. All-or-nothing configuration doesn't allow for granular control
  2. Can't mix strict and lenient validation for different parts of the application
  3. No way to override strictness for specific endpoints or header types

Proposed Changes

Add middleware for dynamic strict mode control:

Acceptance Criteria

  1. Provide middleware for dynamic strict mode control
  2. Add clear documentation for strict mode configuration
  3. Include migration guide for existing applications

Impact Assessment

Affected Components

  • Server configuration
  • Header validation system
  • Request processing pipeline
  • Middleware chain

Examples

Current Implementation

// Current: Global strict mode
final server = await RelicServer.create(
  strictHeaders: true, // Affects all headers
);

Proposed Implementation

const Pipeline().addMiddleware(strictHeadersMiddleware(
  headers: [Headers.authorization],
).addHandler(handler));

This refactoring will provide more flexibility while maintaining security where needed and improving developer experience by allowing precise control over header validation.

Activity

  1. self-assigned this
    on Mar 27, 2025
  2. moved this from Backlog to Now 🔥 in Relic Roadmapon Mar 27, 2025
  3. moved this from Now 🔥 to Next 🌟 in Relic Roadmapon Apr 2, 2025
  4. moved this from Next 🌟 to Later 🥳 in Relic Roadmapon Aug 5, 2025
  5. nielsenko commented on Aug 5, 2025

    @nielsenko
    CollaboratorAuthor

    This is mostly done, but the strict mode flag should die (headers are explicitly validated when accessed via typed HeaderAccessor), and the test structure could do with overhaul.

    Also, we should add convenience middleware that force a subset of headers to be validated up-front..

  6. moved this from Inbox 📫 to Planned 🔭 in Serverpod Frameworkson Aug 14, 2025
  7. moved this from Planned 🔭 to Backlog 🗂️ in Serverpod Frameworkson Aug 28, 2025
  8. moved this from Backlog 🗂️ to Done 🚀 in Serverpod Frameworkson Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions