Encryption & Secure Communication

HTTP Header

About 5 min read

What Is an HTTP Header

An HTTP header is metadata exchanged between a client (browser) and server during HTTP communication, separate from the message body. Request headers travel from client to server, while response headers travel from server to client.

Headers follow a "name: value" format and convey information about content type, caching behavior, authentication credentials, and security policies. Security-related headers are used to have browsers enable specific protective features.

Request Headers vs Response Headers

HTTP headers are broadly divided into two categories based on direction.

Request Headers
Sent from client to server. Include User-Agent (browser type), Accept (acceptable content types), Authorization (authentication tokens), and Cookie (stored cookie data). Servers may use values such as Accept to select which representation to return (proactive negotiation in RFC 9110).
Response Headers
Returned from server to client. Include Content-Type (MIME type), Set-Cookie (cookie instructions), Cache-Control (caching policy), and various security headers.

Additionally, fields such as Date and Connection are used in both directions, and fields such as Content-Length and Content-Encoding describe attributes of the body. The current HTTP specification (RFC 9110) does not use the class names "general header" and "entity header".

Security Headers

Among response headers, security headers that control browser security features are used to enable protections on the browser side.

  • Content-Security-Policy (CSP): Controls which sources a page can load resources from. According to MDN, it is mainly used as a defense against XSS.
  • Strict-Transport-Security (HSTS): HSTS (RFC 6797) is a mechanism by which a website declares that it can be accessed only over secure connections, and browsers then connect to that site over HTTPS only.
  • X-Frame-Options: Controls whether a page can be embedded in an <iframe>. Defends against clickjacking. Set to DENY or SAMEORIGIN. CSP's frame-ancestors directive is the successor, and the CSP Level 3 editor's draft specifies that X-Frame-Options is ignored when frame-ancestors is present.
  • X-Content-Type-Options: Setting nosniff disables browser MIME-type sniffing, preventing the browser from interpreting content differently than the server-specified Content-Type.

These headers work individually and are combined as part of defense in depth.

Cache Control Headers

Cache control headers specify how long browsers and CDNs should retain responses. Proper configuration affects both performance and security.

  • Cache-Control: The header that gives caching instructions. Combines directives like max-age=3600 (cache for 1 hour), no-cache (revalidate with server each time), and no-store (never cache). Pages containing authentication data should use no-store, private.
  • ETag: A value identifying a specific resource version; according to MDN, it is typically a hash of the content, a hash of the last modification timestamp, or a revision number. On subsequent requests, the browser sends the ETag via If-None-Match, and the server returns 304 Not Modified if unchanged, saving bandwidth.
  • Last-Modified / If-Modified-Since: Conditional requests based on last modification time. Similar bandwidth savings to ETag, but the date has one-second resolution. RFC 9110 prefers sending both a strong entity tag and a Last-Modified date.

A common strategy uses long max-age with content-hashed filenames for static assets, and no-cache with ETag validation for HTML pages.

Privacy Headers

From a privacy perspective, several headers are available to control user tracking and data collection.

  • Referrer-Policy: Controls the Referer header content sent during navigation. strict-origin-when-cross-origin (send only origin for cross-origin requests) is the default when no policy is specified (MDN). Limits how much of the page URL is passed to external sites.
  • Permissions-Policy: Controls access to browser features such as camera, microphone, geolocation, and accelerometer. Unused features can be disabled for the document and for embedded iframes. MDN notes that it used to be called Feature-Policy and that the header syntax changed along with the name.
  • Cross-Origin headers: Cross-Origin-Opener-Policy (COOP), Cross-Origin-Embedder-Policy (COEP), and Cross-Origin-Resource-Policy (CORP) control cross-origin resource sharing and window references. MDN's documentation describes COOP as severing references to cross-origin windows and preventing a set of attacks known as XS-Leaks.

Combining security and privacy headers narrows what the browser is allowed to do.

Common Misconceptions

HTTP headers are only relevant to server administrators
Frontend developers also work with HTTP headers. Debugging CORS errors, designing caching strategies, and implementing CSP all require header knowledge. Headers can be inspected in browser developer tools.
Setting security headers eliminates all vulnerabilities
Security headers are one layer of defense in depth. They cannot replace fixing application-level vulnerabilities such as input validation flaws or authentication defects. Headers control browser behavior to reduce attack impact and are meant to be combined with fixing the underlying vulnerabilities.
Share

Related Terms

Related Articles