Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I was working on my node server and encountered the need to implement the use of request.headers.referer. When I did tests and read headers to determine how to write the parsing functions, I couldn't determine a differentiation between requests that invoke from a link coming from outside the server, outside the directory, or calls for local resources from a given HTML response. For instance,

Going from localhost/dir1 to localhost/dir2 using <a href="http://localhost/dir2"> will yield the response headers:

referer:"http://localhost/dir1" url:"/dir2"

while the HTML file sent from localhost/dir2 asking for resources using local URI style.css will yeild:

referer:"http://localhost/dir2" url:"/style.css"

and the same situation involving an image could end up

referer:"http://localhost/dir2" url:"/_images/image.png"

How would I prevent collisions in the resolution, between url and referer, from accidentally resolving to and being parsed as http://localhost/dir1/dir2 or http://localhost/_images/image.png and so on? Is there a way to tell in what way the URI is being referred by the browser, and how can either the browser or server identify when http://localhost/dir2/../dir1 is intended destination?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.