Using Referer Field for Authentication

The referer field in HTTP requests can be easily modified and, as such, is not a valid means of message integrity checking.


Background

The referer field in HTML requests can be simply modified by malicious users, rendering it useless as a means of checking the validity of the request in question.

Demonstrations

The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

The following code samples check a packet's referer in order to decide whether or not an inbound request is from a trusted host.

String trustedReferer = "http://www.example.com/"
while(true){
  n = read(newsock, buffer, BUFSIZE);
  requestPacket = processPacket(buffer, n);
  if (requestPacket.referer == trustedReferer){
    openNewSecureSession(requestPacket);
  }
}
boolean processConnectionRequest(HttpServletRequest request){
  String referer = request.getHeader("referer")
  String trustedReferer = "http://www.example.com/"
  if(referer.equals(trustedReferer)){
    openPrivilegedConnection(request);
    return true;
  }
  else{
    sendPrivilegeError(request);
    return false;
  }
}

These examples check if a request is from a trusted referer before responding to a request, but the code only verifies the referer name as stored in the request packet. An attacker can spoof the referer, thus impersonating a trusted client.

See Also

Comprehensive Categorization: Access Control

Weaknesses in this category are related to access control.

Authenticate Actors

Weaknesses in this category are related to the design and architecture of authentication components of the system. Frequently these deal with verifying the entity is i...

SFP Secondary Cluster: Faulty Endpoint Authentication

This category identifies Software Fault Patterns (SFPs) within the Faulty Endpoint Authentication cluster (SFP29).

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.


Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.