Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are these extra HTTP headers coming from?

When I simply echo something out of php file, I do not send any headers intentionally, however - there are some default headers present anyway when I look at firebug response:

response headers:

HTTP/1.1 200 OK
Server: nginx
Date: Thu, 23 Jun 2011 19:33:51 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.3.6-6~dotdeb.1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Encoding: gzip

I'm curious - are these default response headers set by the server(nginx) or by PHP?

like image 990
Stann Avatar asked Jun 23 '11 20:06

Stann


People also ask

Where do request headers come from?

HTTP Request fields. These header lines are sent by the client in a HTTP protocol transaction. All lines are RFC822 format headers.

Can HTTP headers be hacked?

HTTP Host header attacks exploit vulnerable websites that handle the value of the Host header in an unsafe way. If the server implicitly trusts the Host header, and fails to validate or escape it properly, an attacker may be able to use this input to inject harmful payloads that manipulate server-side behavior.

How many extra response header information we get by default when enabling the expose headers information?

The HTTP Access-Control-Expose-Headers header is a response header that is used to expose the headers that have been mentioned in it. By default 6 response headers are already exposed which are known as CORS-safelisted response headers.

Are HTTP headers safe?

HTTP security headers are a fundamental part of website security. Upon implementation, they protect you against the types of attacks that your site is most likely to come across. These headers protect against XSS, code injection, clickjacking, etc.


2 Answers

I believe it is a combination of both... You can tell that "X-Powered-By: PHP/5.3.6-6~dotdeb.1" comes from PHP and "Server: nginx" comes from NGINX.

You can alter the headers in PHP as follows:

<?php
    header("HTTP/1.0 404 Not Found");
?>

The gzip header most definitely comes from NGINX as it is compressing the output (html) to the browser. PHP can "add" to the headers by calling a function like the one above. Then the server combines it with the PHP headers and serves the request.

It depends on your server whether or not the PHP headers take precedence over the server headers.

Hope this helps.

like image 133
Jeffrey Kevin Pry Avatar answered Sep 19 '22 21:09

Jeffrey Kevin Pry


The majority are set by nginx, for example the Server, Date, Content-Encoding, and Connection. However, some other headers are set by PHP, and you can add others in PHP like this header("Name: Value");

like image 31
Andrea Avatar answered Sep 18 '22 21:09

Andrea