roc-lang / roc-lang/basic-webserver

Add an explicit global browser security-response-header policy

Open
#200 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
107
Forks
20
Avg merge
1d 17h
Merged PRs (30d)
11

Description

Summary

Add a typed, immutable policy to Server.Config for security headers which should apply consistently to Roc responses, native file responses, probes, and host-generated errors.

Illustrative configuration:

security_headers: SecurityHeaders.policy({
    content_type_options: Nosniff,
    referrer_policy: StrictOriginWhenCrossOrigin,
    frame_options: Deny,
    opener_policy: Disabled,
    hsts: Disabled,
})

The default must preserve current behavior: no security headers are enabled implicitly.

Why this belongs in the platform

Several browser security headers are easy to serialize incorrectly or omit from non-application responses. basic-webserver itself serves native files and native operational routes, so a helper applied only inside respond! cannot cover the entire server.

Django makes the same deployment observation: security headers are most effective at a layer that covers application and non-application responses.

An immutable startup policy is a better fit than a general middleware runtime. The host only applies prevalidated headers; it does not run application callbacks.

Initial scope

Typed support for:

  • X-Content-Type-Options: nosniff
  • Referrer-Policy
  • X-Frame-Options: DENY | SAMEORIGIN
  • Cross-Origin-Opener-Policy
  • Strict-Transport-Security, including max age, includeSubDomains, and preload

Rules:

  • Header names are matched case-insensitively.
  • A response's explicit value takes precedence over the global policy.
  • The host must not emit duplicate managed headers accidentally.
  • HSTS is opt-in, never inferred from Forwarded or X-Forwarded-Proto, and prominently documented as a domain-wide deployment decision.
  • HSTS should normally be configured at the public TLS-terminating proxy when one exists.
  • Avoid deprecated or harmful headers such as HPKP and Expect-CT.
  • Do not claim that the policy makes an application "secure".

Content Security Policy is intentionally excluded initially. A useful CSP depends on the application's scripts, styles, framing, reporting, and nonce strategy; a generic preset is likely either ineffective or application-breaking.

Tests

  • All response paths, including native files, probes, and generated errors.
  • Case-insensitive conflict detection and per-response precedence.
  • Exact serialization for every typed policy value.
  • HSTS validation and disabled behavior.
  • No duplicate headers across HTTP/1.1 and HTTP/2.

Acceptance criteria

  • A startup policy can apply selected headers to every host-produced response.
  • Every policy is opt-in and typed.
  • Dynamic responses can override a managed header explicitly.
  • HSTS carries clear proxy, certificate, and whole-domain warnings.
  • CSP and deprecated security headers are not hidden inside a misleading preset.

References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Server.Config and each host-produced response path named in the issue: Roc responses, native files, probes, and generated errors. Review the existing response-header handling and test coverage, then define completion against the listed typed policies, precedence, validation, serialization, and duplicate-header acceptance criteria.

Written by the indexing model from the issue text.

Assessment

Domain
backend-api-design, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.