>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:
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to