Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Dec 2013 23:57:38 GMT
From:      Jan Beich <jbeich@tormail.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/184507: [patch] libfetch: allow hiding User-Agent with empty string
Message-ID:  <201312042357.rB4NvcpN003567@oldred.freebsd.org>
Resent-Message-ID: <201312050000.rB5000JB022498@freefall.freebsd.org>

index | next in thread | raw e-mail


>Number:         184507
>Category:       bin
>Synopsis:       [patch] libfetch: allow hiding User-Agent with empty string
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 05 00:00:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Jan Beich
>Release:        
>Organization:
>Environment:
>Description:
In some situations it may be desirable to completely hide User-Agent field
when fetching a file e.g., when using over Tor.

>How-To-Repeat:
$ sudo nc -kl 0 80 &

# before
$ HTTP_USER_AGENT= fetch http://0
GET / HTTP/1.1
Host: 0
Accept: */*
User-Agent: fetch libfetch/2.0
Connection: close
^C

# after
$ HTTP_USER_AGENT= fetch http://0
GET / HTTP/1.1
Host: 0
Accept: */*
Connection: close
^C

# other download tools

$ curl -A "" http://0
GET / HTTP/1.1
Host: 0
Accept: */*
^C

$ wget -U "" http://0 2>/dev/null
GET / HTTP/1.1
Accept: */*
Host: 0
Connection: Keep-Alive
^C

>Fix:
--- noua.diff begins here ---
Index: lib/libfetch/fetch.3
===================================================================
--- lib/libfetch/fetch.3	(revision 258921)
+++ lib/libfetch/fetch.3	(working copy)
@@ -627,6 +627,7 @@ the document URL will be used as referrer URL.
 Specifies the User-Agent string to use for HTTP requests.
 This can be useful when working with HTTP origin or proxy servers that
 differentiate between user agents.
+If used with an empty string no User-Agent is sent.
 .It Ev NETRC
 Specifies a file to use instead of
 .Pa ~/.netrc
Index: lib/libfetch/http.c
===================================================================
--- lib/libfetch/http.c	(revision 258921)
+++ lib/libfetch/http.c	(working copy)
@@ -1679,9 +1679,10 @@ http_request(struct url *URL, const char *op, stru
 			else
 				http_cmd(conn, "Referer: %s", p);
 		}
-		if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0')
-			http_cmd(conn, "User-Agent: %s", p);
-		else
+		if ((p = getenv("HTTP_USER_AGENT")) != NULL) {
+			if  (*p != '\0')
+				http_cmd(conn, "User-Agent: %s", p);
+		} else
 			http_cmd(conn, "User-Agent: %s " _LIBFETCH_VER, getprogname());
 		if (url->offset > 0)
 			http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
--- noua.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312042357.rB4NvcpN003567>