HTTP 414 Request-URI Too Long
Overview
The HTTP 414 URI Too Long
status code indicates that the server is refusing to service the request because the URI (Uniform Resource Identifier) is longer than the server is willing or able to interpret.
Purpose
The HTTP 414 response is often used when a client sends an excessively long URI, which could be an attempt at a buffer overflow attack or simply a mistakenly constructed request.
Usage
Client Behavior:
- Send Request with Long URI: The client sends an HTTP request with an unusually long URI.
- Receive Response: The client receives the HTTP 414 status code, indicating the URI is too long for the server to process.
Server Behavior:
- Evaluate URI Length: The server checks the length of the request URI.
- Send Response: If the URI exceeds the server’s acceptable length, the server responds with a
414 URI Too Long
status code.
Scenarios
- Excessively Long Query Strings: URLs with extremely long query parameters.
- Buffer Overflow Attacks: Potential security threats where attackers use long URIs.
Sequence Diagram
Illustrating the process for an HTTP 414 response:
sequenceDiagram participant Client participant Server as Web Server Note over Client: Client sends a request with an excessively long URI Client->>Server: GET /very/long/uri?with=query¶meters=... HTTP/1.1 Note over Server: Server evaluates URI length Server->>Client: HTTP/1.1 414 URI Too Long
Curl Request and Response Example
Simulating an excessively long URI request using Curl:
curl -i http://example.com/very/long/uri?with=query¶meters=...
# Expected response: HTTP/1.1 414 URI Too Long
PHP cURL Request and Response Example
PHP script using cURL to simulate a 414 URI Too Long response:
<?php
$longUri = 'http://example.com/' . str_repeat('a', 2000); // Simulating a long URI
$ch = curl_init($longUri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 414) {
echo "URI too long.";
}
curl_close($ch);
?>
Python Request and Response Example
Python script to send a GET request with an excessively long URI and handle a 414 response:
import requests
longUri = 'http://example.com/' + 'a' * 2000 # Simulating a long URI
response = requests.get(longUri)
if response.status_code == 414:
print("URI too long")
Apache Configuration for HTTP 414 URI Too Long
Configuring Apache to handle requests with long URIs:
<VirtualHost *:80>
ServerName example.com
# Apache may handle long URIs by default, but specific limits and behaviors can be set
# ...
</VirtualHost>
NGINX Configuration for HTTP 414 URI Too Long
Setting up NGINX to respond to requests with excessively long URIs:
server {
listen 80;
server_name example.com;
# NGINX has a default limit for URI length, which can be adjusted
large_client_header_buffers 4 16k; # Adjust buffer size as needed
# ...
}
HTTP 413 Request Entity Too Large HTTP 415 Unsupported Media Type