Skip to content

Commit

Permalink
inets: Add value 'none' in server_tokens config
Browse files Browse the repository at this point in the history
When the Server header has empty info (or 'none' in config), it is not generated.  This is for limiting Banner Grabbing attempts.
  • Loading branch information
HansN committed Apr 21, 2015
1 parent bbac101 commit ab9c37a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/inets/doc/src/httpd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,15 @@ text/plain asc txt
</item>

<marker id="prop_server_tokens"></marker>
<tag>{server_tokens, prod|major|minor|minimal|os|full|{private, string()}}</tag>
<tag>{server_tokens, none|prod|major|minor|minimal|os|full|{private, string()}}</tag>
<item>
<p>ServerTokens defines how the value of the server header
should look. </p>
<p>Example: Assuming the version of inets is 5.8.1,
here is what the server header string could look like for
the different values of server-tokens: </p>
<pre>
none "" % A Server: header will not be generated
prod "inets"
major "inets/5"
minor "inets/5.8"
Expand Down
8 changes: 5 additions & 3 deletions lib/inets/src/http_server/httpd_conf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ load("ServerName " ++ ServerName, []) ->

load("ServerTokens " ++ ServerTokens, []) ->
%% These are the valid *plain* server tokens:
%% sprod, major, minor, minimum, os, full
%% none, prod, major, minor, minimum, os, full
%% It can also be a "private" server token: private:<any string>
case string:tokens(ServerTokens, [$:]) of
["private", Private] ->
{ok,[], {server_tokens, clean(Private)}};
[TokStr] ->
Tok = list_to_atom(clean(TokStr)),
case lists:member(Tok, [prod, major, minor, minimum, os, full]) of
case lists:member(Tok, [none, prod, major, minor, minimum, os, full]) of
true ->
{ok,[], {server_tokens, Tok}};
false ->
Expand Down Expand Up @@ -850,6 +850,8 @@ server(full = _ServerTokens) ->
OS = os_info(full),
lists:flatten(
io_lib:format("~s ~s OTP/~s", [?SERVER_SOFTWARE, OS, OTPRelease]));
server(none = _ServerTokens) ->
"";
server({private, Server} = _ServerTokens) when is_list(Server) ->
%% The user provide its own
Server;
Expand Down Expand Up @@ -1299,7 +1301,7 @@ ssl_ca_certificate_file(ConfigDB) ->
end.

plain_server_tokens() ->
[prod, major, minor, minimum, os, full].
[none, prod, major, minor, minimum, os, full].

error_report(Where,M,F,Error) ->
error_logger:error_report([{?MODULE, Where},
Expand Down
7 changes: 5 additions & 2 deletions lib/inets/src/http_server/httpd_response.erl
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,11 @@ create_header(ConfigDb, KeyValueTupleHeaders) ->
ContentType = "text/html",
Server = server(ConfigDb),
NewHeaders = add_default_headers([{"date", Date},
{"content-type", ContentType},
{"server", Server}],
{"content-type", ContentType}
| if Server=="" -> [];
true -> [{"server", Server}]
end
],
KeyValueTupleHeaders),
lists:map(fun fix_header/1, NewHeaders).

Expand Down
2 changes: 1 addition & 1 deletion lib/inets/vsn.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
# %CopyrightEnd%

APPLICATION = inets
INETS_VSN = 5.10.6
INETS_VSN = 5.10.7
PRE_VSN =
APP_VSN = "$(APPLICATION)-$(INETS_VSN)$(PRE_VSN)"

0 comments on commit ab9c37a

Please sign in to comment.