Skip to content

improve baseline HTTP security for no-reverse proxy deployment scenarios#2782

Merged
wojcik91 merged 14 commits intorelease/2.0from
http_security
Apr 23, 2026
Merged

improve baseline HTTP security for no-reverse proxy deployment scenarios#2782
wojcik91 merged 14 commits intorelease/2.0from
http_security

Conversation

@wojcik91
Copy link
Copy Markdown
Contributor

@wojcik91 wojcik91 commented Apr 23, 2026

  • added baseline security headers
  • HSTS only sent when the server is running with TLS
  • added request body size limit
  • added request timeout
  • IP-based rate limiter (mirroring proxy approach)
  • Cache-Control: no-store for API routes

Also forces uuid >14 frontend dependency to resolve trivy warning.

Resolves https://github.com/DefGuard/internal/issues/66

@wojcik91 wojcik91 self-assigned this Apr 23, 2026
@wojcik91 wojcik91 requested a review from Copilot April 23, 2026 06:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves DefGuard Core’s baseline HTTP hardening for deployments where Core is exposed directly (no reverse proxy), by adding security headers, request limits, and per-IP rate limiting with sensible defaults.

Changes:

  • Add a centralized security-headers middleware (incl. TLS-aware HSTS) and plumb TLS state via AppState.
  • Apply global request body size limits (with a larger per-route override for network import) and a global request timeout that excludes SSE streams.
  • Introduce per-IP rate limiting via tower_governor, configurable via new DEFGUARD_RATELIMIT_* env vars.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/defguard_core/src/lib.rs Adds timeout + body limits, restructures SSE routing, wires security headers middleware, and adds rate limiting in run_web_server.
crates/defguard_core/src/headers.rs Implements security headers middleware and makes HSTS conditional on TLS.
crates/defguard_core/src/appstate.rs Adds tls_active: Arc<AtomicBool> to app state.
crates/defguard_common/src/config.rs Adds CLI/env config for rate limiting parameters.
crates/defguard_core/Cargo.toml Adds tower_governor dependency.
Cargo.toml Adds tower_governor to workspace deps and switches tower-http features to include timeout.
crates/defguard_setup/src/migration.rs Updates AppState::new call-site with the new tls_active argument.
crates/defguard_core/tests/integration/api/common/mod.rs Updates build_webapp call-site for new tls_active argument.
crates/defguard_core/tests/integration/api/proxy_certs.rs Updates build_webapp call-site for new tls_active argument.
Cargo.lock Locks new dependencies pulled in by tower_governor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/defguard_core/src/lib.rs
Comment thread crates/defguard_core/src/lib.rs Outdated
Comment thread crates/defguard_core/src/lib.rs
@wojcik91 wojcik91 marked this pull request as ready for review April 23, 2026 09:43
@wojcik91 wojcik91 merged commit 8e4944a into release/2.0 Apr 23, 2026
13 checks passed
@wojcik91 wojcik91 deleted the http_security branch April 23, 2026 13:03
This was referenced Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants