Post

Understanding request and response

Understanding request and response

โœ… Security Headers (Response)

These help protect against XSS, clickjacking, MIME sniffing, and enforce secure communication.

HeaderPurpose
Strict-Transport-SecurityForces HTTPS for all requests (HSTS).
Content-Security-PolicyControls resources the user agent is allowed to load.
X-Content-Type-Options: nosniffPrevents MIME sniffing.
X-Frame-Options: DENY / SAMEORIGINPrevents clickjacking (iframe embedding).
X-XSS-Protection: 1; mode=blockEnables browser XSS filter (legacy).
Referrer-PolicyControls how much referrer info is sent.
Permissions-PolicyControls access to browser features like camera, mic, geolocation.
Cross-Origin-Embedder-PolicyEnforces stricter isolation for cross-origin resources.
Cross-Origin-Opener-PolicyPrevents window from being shared with cross-origin content.
Cross-Origin-Resource-PolicyControls sharing of resources with other origins.
Set-Cookie: Secure; HttpOnly; SameSite=StrictProtects cookies from XSS and CSRF.
X-Permitted-Cross-Domain-PoliciesRestricts Flash/Adobe cross-domain policies.
X-Download-Options: noopenPrevents file auto-open in IE.

๐ŸŒ CORS Headers (Response)

These control cross-origin access to resources.

HeaderPurpose
Access-Control-Allow-OriginSpecifies allowed origins.
Access-Control-Allow-CredentialsAllows cookies/auth headers in CORS requests.
Access-Control-Allow-MethodsSpecifies allowed HTTP methods for CORS.
Access-Control-Allow-HeadersSpecifies allowed custom headers.
Access-Control-Expose-HeadersAllows specific response headers to be accessed by client.
Vary: OriginEnsures correct caching based on origin.

๐Ÿ”’ Security-Relevant Request Headers

HeaderPurpose
AuthorizationSends credentials (Basic, Bearer tokens).
CookieSends cookies (can be secured with flags).
OriginIndicates origin of the cross-site request.
RefererTells server which page made the request.
User-AgentIdentifies client software (can be fingerprinted).
HostSpecifies the domain being accessed.
X-Requested-WithUsed in AJAX requests to detect JavaScript-based access.
Forwarded / X-Forwarded-For / X-Real-IPReveal clientโ€™s original IP in proxied setups.

๐Ÿšฆ Rate Limiting & Abuse Protection (Response)

HeaderPurpose
X-RateLimit-LimitMax number of requests allowed.
X-RateLimit-RemainingRequests remaining in window.
X-RateLimit-ResetTime when the rate limit resets.
Retry-AfterSuggests when to retry after rate limiting or 503.

โšก Performance & Caching Headers

HeaderPurpose
Cache-ControlControls caching behavior (e.g., no-store, public).
ETagIdentifier for a specific version of a resource.
Last-ModifiedTimestamp of last resource update.
ExpiresDate/time after which response is considered stale.
VaryInstructs caches to vary based on request headers.
Transfer-Encoding: chunkedAllows streaming responses in chunks.

๐Ÿ“ฆ Content & File Management Headers

HeaderPurpose
Content-TypeMIME type of the resource.
Content-LengthSize of the body in bytes.
Content-DispositionControls if content is inline or attachment (download).
Content-EncodingIndicates compression method (e.g., gzip, br).
AcceptMedia types the client accepts.
Accept-EncodingCompression types client supports.
Accept-LanguageLanguages the client prefers.

๐Ÿ” Redirection & Response Control

HeaderPurpose
LocationUsed with 3xx responses to redirect.
Retry-AfterUsed with 429/503 to indicate retry time.
LinkPreloading resources, pagination, etc.

๐Ÿ› ๏ธ Custom Headers (X-Headers)

HeaderPurpose
X-Request-ID / X-Correlation-IDTrace a request across systems.
X-Powered-ByReveals backend tech (often removed for security).
X-App-VersionIndicates the API or app version.

Headers from DHL:

  1. HttpOnly - Mitigates XSS
  2. no-cache: Forces revalidation with the server before use.
  3. no-store: Donโ€™t store any part of the response.
  4. max-age=0: The response is immediately stale.
  5. must-revalidate: Client must validate the response with the server before using cached data.

    CORS (Cross-Origin Resource Sharing) Headers

Vary: Access-Control-Request-Headers

  • Instructs caches to consider request headers like Access-Control-Request-Headers when deciding if a cached response is valid. Access-Control-Expose-Headers: Authorization
  • Allows the client (JavaScript) to access the Authorization header in the response. Access-Control-Allow-Credentials: true
  • Indicates that the response can be shared with requests that include credentials (like cookies, HTTP auth). Access-Control-Allow-Origin: *
  • Allows any domain to access the resource. Not recommended with Allow-Credentials: true

Rate Limiting Headers

X-RateLimit-Remaining: -1

  • Indicates how many requests are remaining in the current rate limit window. -1 may mean unlimited or rate limit not enforced. X-RateLimit-Requested-Tokens: 1
  • Custom header indicating how many tokens (or cost) this request used. X-RateLimit-Burst-Capacity: 50
  • Max number of requests that can be made in a burst. X-RateLimit-Replenish-Rate: 25
  • How quickly the token bucket is refilled (requests per second/minute etc.).

Security Headers

X-XSS-Protection: 1; mode=block

  • Enables XSS filter in some browsers and blocks detected attacks. Strict-Transport-Security: max-age=631138519
  • Enforces HTTPS connections for a specified period (in seconds). Helps prevent man-in-the-middle attacks. X-Frame-Options: DENY
  • Prevents the page from being embedded in an iframe (clickjacking protection). X-Content-Type-Options: nosniff
  • Prevents browsers from MIME-sniffing a response away from the declared content type. Referrer-Policy: no-referrer
  • Specifies that the browser should not send any Referer header. Content-Security-Policy: default-src 'none'
  • Restricts where resources (scripts, images, etc.) can be loaded from. 'none' blocks everything unless overridden. X-Download-Options: noopen
  • Prevents file downloads from automatically opening in Internet Explorer. X-Permitted-Cross-Domain-Policies: none
  • Restricts Flash/Adobe PDF cross-domain data loading policies.
This post is licensed under CC BY 4.0 by the author.

Trending Tags