This content was extracted from HTB Academy

General Headers

General headersย are used in both HTTP requests and responses. They are contextual and are used toย describe the message rather than its contents.

HeaderExampleDescription
DateDate: Wed, 16 Feb 2022 10:38:44 GMTHolds the date and time at which the message originated. Itโ€™s preferred to convert the time to the standardย UTCย time zone.
ConnectionConnection: closeDictates if the current network connection should stay alive after the request finishes. Two commonly used values for this header areย closeย andย keep-alive. Theย closeย value from either the client or server means that they would like to terminate the connection, while theย keep-aliveย header indicates that the connection should remain open to receive more data and input.

Entity Headers

Similar to general headers,ย Entity Headersย can beย common to both the request and response. These headers are used toย describe the contentย (entity) transferred by a message. They are usually found in responses and POST or PUT requests.

HeaderExampleDescription
Content-TypeContent-Type: text/htmlUsed to describe the type of resource being transferred. The value is automatically added by the browsers on the client-side and returned in the server response. Theย charsetย field denotes the encoding standard, such asย UTF-8.
Media-TypeMedia-Type: application/pdfTheย media-typeย is similar toย Content-Type, and describes the data being transferred. This header can play a crucial role in making the server interpret our input. Theย charsetย field may also be used with this header.
Boundaryboundary="b4e4fbd93540"Acts as a marker to separate content when there is more than one in the same message. For example, within a form data, this boundary gets used asย --b4e4fbd93540ย to separate different parts of the form.
Content-LengthContent-Length: 385Holds the size of the entity being passed. This header is necessary as the server uses it to read data from the message body, and is automatically generated by the browser and tools like cURL.
Content-EncodingContent-Encoding: gzipData can undergo multiple transformations before being passed. For example, large amounts of data can be compressed to reduce the message size. The type of encoding being used should be specified using theย Content-Encodingย header.

Request Headers

The client sendsย Request Headersย in an HTTP transaction. These headers areย used in an HTTP request and do not relate to the contentย of the message. The following headers are commonly seen in HTTP requests.

HeaderExampleDescription
HostHost: www.inlanefreight.comUsed to specify the host being queried for the resource. This can be a domain name or an IP address. HTTP servers can be configured to host different websites, which are revealed based on the hostname. This makes the host header an important enumeration target, as it can indicate the existence of other hosts on the target server.
User-AgentUser-Agent: curl/7.77.0Theย User-Agentย header is used to describe the client requesting resources. This header can reveal a lot about the client, such as the browser, its version, and the operating system.
RefererReferer: http://www.inlanefreight.com/Denotes where the current request is coming from. For example, clicking a link from Google search results would makeย https://google.comย the referer. Trusting this header can be dangerous as it can be easily manipulated, leading to unintended consequences.
AcceptAccept: */*Theย Acceptย header describes which media types the client can understand. It can contain multiple media types separated by commas. Theย */*ย value signifies that all media types are accepted.
CookieCookie: PHPSESSID=b4e4fbd93540Contains cookie-value pairs in the formatย name=value. Aย cookieย is a piece of data stored on the client-side and on the server, which acts as an identifier. These are passed to the server per request, thus maintaining the clientโ€™s access. Cookies can also serve other purposes, such as saving user preferences or session tracking. There can be multiple cookies in a single header separated by a semi-colon.
AuthorizationAuthorization: BASIC cGFzc3dvcmQKAnother method for the server to identify clients. After successful authentication, the server returns a token unique to the client. Unlike cookies, tokens are stored only on the client-side and retrieved by the server per request. There are multiple types of authentication types based on the webserver and application type used.
A complete list of request headers and their usage can be foundย here.

Response Headers

Response Headersย can beย used in an HTTP response and do not relate to the content. Certain response headers such asย Age,ย Location, andย Serverย are used to provide more context about the response. The following headers are commonly seen in HTTP responses.

HeaderExampleDescription
ServerServer: Apache/2.2.14 (Win32)Contains information about the HTTP server, which processed the request. It can be used to gain information about the server, such as its version, and enumerate it further.
Set-CookieSet-Cookie: PHPSESSID=b4e4fbd93540Contains the cookies needed for client identification. Browsers parse the cookies and store them for future requests. This header follows the same format as theย Cookieย request header.
WWW-AuthenticateWWW-Authenticate: BASIC realm="localhost"Notifies the client about the type of authentication required to access the requested resource.

Security Headers

Finally, we haveย Security Headers. With the increase in the variety of browsers and web-based attacks, defining certain headers that enhanced security was necessary. HTTP Security headers areย a class of response headers used to specify certain rules and policiesย to be followed by the browser while accessing the website.

HeaderExampleDescription
Content-Security-PolicyContent-Security-Policy: script-src 'self'Dictates the websiteโ€™s policy towards externally injected resources. This could be JavaScript code as well as script resources. This header instructs the browser to accept resources only from certain trusted domains, hence preventing attacks such asย Cross-site scripting (XSS).
Strict-Transport-SecurityStrict-Transport-Security: max-age=31536000Prevents the browser from accessing the website over the plaintext HTTP protocol, and forces all communication to be carried over the secure HTTPS protocol. This prevents attackers from sniffing web traffic and accessing protected information such as passwords or other sensitive data.
Referrer-PolicyReferrer-Policy: originDictates whether the browser should include the value specified via theย Refererย header or not. It can help in avoiding disclosing sensitive URLs and information while browsing the website.

Note

This section only mentions a small subset of commonly seen HTTP headers. There are many other contextual headers that can be used in HTTP communications. Itโ€™s also possible for applications to define custom headers based on their requirements. A complete list of standard HTTP headers can be foundย here.