Skip to content

feat(security): add configurable default HTTP security headers#48

Merged
angga7togk merged 1 commit into
GamanJS:v2from
fiandev:issues/47-security-headers-middleware
May 4, 2026
Merged

feat(security): add configurable default HTTP security headers#48
angga7togk merged 1 commit into
GamanJS:v2from
fiandev:issues/47-security-headers-middleware

Conversation

@fiandev
Copy link
Copy Markdown
Contributor

@fiandev fiandev commented May 4, 2026

Add Security Headers Middleware

This PR adds a setSecurity method to the Gaman class that allows configuring security headers for all responses.
Changes

  • New SecurityOptions interface in src/types.ts with support for:
    • contentSecurityPolicy - CSP header
    • xFrameOptions - X-Frame-Options header
    • hsts - Strict-Transport-Security with maxAge, includeSubDomains, preload
    • noSniff - X-Content-Type-Options
    • referrerPolicy - Referrer-Policy header
    • xssFilter - X-XSS-Protection header
    • crossOriginOpenerPolicy - COOP header
    • crossOriginEmbedderPolicy - COEP header
    • crossOriginResourcePolicy - CORP header
    • cacheControl - Cache-Control header
    • xPermittedCrossDomainPolicies - X-Permitted-Cross-Domain-Policies
    • xDownloadOptions - X-Download-Options
  • New setSecurity(options) method - Store security options
  • Updated mountServer() - Added optional security parameter to apply security headers on server start
  • Updated handleResponse() - Applies security headers to all responses
  • Renamed ambiguous variable - Changed h to httpConfig in mountServer

How it's looks like:

const app = new Gaman();
		
app.setSecurity({
	xFrameOptions: 'DENY',
	noSniff: true,
});

also can be like this:

const app = new Gaman();
app.mountServer({ http: 3431 }, { xFrameOptions: 'DENY', noSniff: true });

Ref: #47

Ref: GamanJS#47

Co-authored-by: gemini-cli gemini-2.5-flash <218195315+gemini-cli@users.noreply.github.com>
@fiandev
Copy link
Copy Markdown
Contributor Author

fiandev commented May 4, 2026

@angga7togk bruh di local aman jir test case nya

@angga7togk
Copy link
Copy Markdown
Member

udah di test kah banh ?

@fiandev
Copy link
Copy Markdown
Contributor Author

fiandev commented May 4, 2026

udah di test kah banh ?

dilocal aman cik

@angga7togk angga7togk merged commit 4f8348d into GamanJS:v2 May 4, 2026
2 of 4 checks passed
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.

2 participants