Commit Graph

38 Commits

Author SHA1 Message Date
Christien Rioux
64d9f456ce
Merge branch 'address-localhost-disk-consumption-attack' into 'main'
Avoid large logs of 127.0.0.1:5959 attack payloads

See merge request veilid/veilid!158
2023-09-03 00:32:29 +00:00
Christien Rioux
e302b764d0 docs and tests work 2023-08-29 15:15:47 -05:00
Rivka Segan
4873a0c0c9 Avoid large logs of 127.0.0.1:5959 attack payloads
Because veilid-server listens on 127.0.0.1 TCP port 5959, it is
potentially open to attacks from websites if a user runs an ordinary
web browser (e.g., Chrome or Firefox) on the same computer.
Specifically, any https website can include JavaScript code that
begins with

   let message = 'WASTE_YOUR_VEILID_SERVER_DISK_SPACE_'.repeat(1000);

   fetch('http://127.0.0.1:5959/' + message)

and the web browser will then send many KB of data to veilid-server,
where it may typically be logged to disk by this code:
2ab51ae3e9/veilid-core/src/veilid_api/serialize_helpers/serialize_json.rs (L6-L12)

(Because Veilid hasn't even reached 1.0, it's very common for users to
enable a large amount of logging.)

The threat model is that someone creates a website that's apparently
of interest to any Veilid user, but the actual purpose of the website
is to leverage the user's web browser to silently tunnel an attack
payload into another application that is local to the user. An attack
that sends more than 1 MB of data (for each fetch API call) is
feasible, and the patch in this MR tries to address that.

Note that the most common web browsers always allow JavaScript on
arbitrary https websites to send data to 127.0.0.1 port 5959, there is
no configuration menu to shut this off, and the user is not alerted
that this is occurring. Brave 1.54 (June 2023) was the first popular
web browser to block this:
https://brave.com/privacy-updates/27-localhost-permission/

This does not mean that an adversary can just as easily setup a
website to send:

  {"op":"Control","args":["Shutdown"],"id":1}

to 127.0.0.1 TCP port 5959 and thereby terminate a veilid-server
process. A web browser using http will always send requests that begin
with specific strings (such as GET or OPTIONS) on the first line, and
the code at:

2ab51ae3e9/veilid-server/src/client_api.rs (L367)

2ab51ae3e9/veilid-server/src/client_api.rs (L244)

2ab51ae3e9/veilid-server/src/client_api.rs (L202)

seems to work together to ensure that no JSON object results in
command execution unless the first line of the input is a JSON object.
(Not sure if this was a design goal, or simply how it turned out.)

A web browser can do other things besides cleartext http (e.g., try to
start a TLS session to 127.0.0.1 TCP port 5959), but it's perhaps
unlikely that the initial bytes of the network traffic, in the context
of the above threat model, would ever be a JSON object.

Note that, although veilid-server is not speaking the HTTP protocol on
127.0.0.1 TCP port 5959, it is still able to read the data sent by any
web browser to http://127.0.0.1:5959, send that data to a JSON parser,
and write the data to the server logs. In limited testing, the HTTP
client typically saw zero bytes of application layer response;
however, if the HTTP client sent a huge amount of data (e.g., 16 MB),
the HTTP client would sometimes receive a large response with JSON
data about veilid-server's internal state. That might be a separate
bug. In the context of the threat model, this may not matter because
that JSON data isn't accessible by the operator of the website (that
hosts the JavaScript code).

There may be many ways to resolve this. First, the Veilid
documentation could recommend never running a web browser on any
machine that has veilid-server with 127.0.0.1 TCP port 5959 open.
Second, the existence of a realistically probe-able service on
127.0.0.1 TCP port 5959 might be considered much too large an attack
surface for an application of Veilid's sensitivity, and interprocess
communication could be replaced with something other than
unauthenticated TCP.

This MR is intended to improve Veilid for an ordinary user who wants
to help the project by installing veilid-server on their primary
personal machine, and wants veilid-cli to remain usable, but needs to
continue routine web browsing on that machine. It provides safer
behavior for such a person. The MR is not intended to benefit experts
who already understand localhost TCP risks, and either avoid all web
browsing on the same machine or have their own countermeasures. These
experts will not see any attacker-controlled traffic on port 5959, and
thus the reduction in logging should be of no concern to them.

Without the patch (and with logging on), data sent by a web browser is
always logged by veilid-server in the form:

   Connection processing failure: Parse error: 'expected value at line 1 column 1' with value 'deserialize_json:
   ---
   GET /<attacker_controlled_data> HTTP/1.1
   ---
    to type veilid_core::veilid_api::json_api::Request'

regardless of how long the attacker controlled data is. Some browsers
such as Chrome start by sending OPTIONS instead of GET.

With the patch, long malformed input is discarded and the log instead
contains:

   Connection processing failure: Parse error: 'expected value at line 1 column 1' with value 'deserialize_json:
   ---
   :skipped long input that's not a JSON object
   ---
    to type veilid_core::veilid_api::json_api::Request'

The patch allows logging of anything where the first non-whitespace
character is a '{' - this is considered safe (at the moment) because
no web browser (realistically used by a local user) can send '{' at
the beginning of the first line. Also, the patch allows logging of
requests smaller than 50 bytes to support two use cases. First, if a
node operator is sending one of the simple JSON API requests by hand
and is accidentally omitting the initial '{' from the JSON object,
they'll be able to see the failure in their logs. Second, non-expert
node operators may want some limited visibility into the details of
adversarial activity on http://127.0.0.1:5959. Of course, this default
logging policy could be made more flexible later if Veilid decides to
stay with unauthenticated TCP. The patch only aims to defeat a simple
DoS attack against the out-of-the-box code.
2023-08-28 04:53:31 +00:00
John Smith
234f048241 simplify tracing 2023-06-24 22:59:51 -04:00
John Smith
d6f442d431 better error handling 2023-06-15 20:22:54 -04:00
John Smith
615e0ca1d0 more tests 2023-06-14 21:06:10 -04:00
John Smith
532bcf2e2a json api cli working 2023-06-09 19:08:49 -04:00
John Smith
419bfcd8ce checkpoint 2023-06-08 14:07:09 -04:00
John Smith
317f036598 server api 2023-06-07 17:39:10 -04:00
John Smith
88db69c28f checkpoint 2023-06-06 19:09:29 -04:00
John Smith
0a890c8707 removing dev branch, many changes 2023-05-29 19:24:57 +00:00
John Smith
16d74b96f3 alignment refactor 2022-12-16 21:55:03 -05:00
John Smith
688995ed0d pr work 2022-11-16 12:49:53 -05:00
John Smith
baf1353fd2 test 2022-11-11 18:00:11 -05:00
John Smith
046b61d5d8 more app message call 2022-09-30 22:37:55 -04:00
John Smith
36f95692f6 fix relay 2022-07-05 19:47:25 -04:00
John Smith
c106d324c8 api and log refactor 2022-07-01 12:13:52 -04:00
John Smith
e49f7a89c0 simplify futures 2022-06-29 10:34:23 -04:00
John Smith
018d7da429 fix tokio 2022-06-29 10:13:49 -04:00
John Smith
fdbb4c6397 executor work 2022-06-27 23:46:29 -04:00
John Smith
5931f1254f flutter and macos work 2022-06-10 17:07:10 -04:00
John Smith
1d8c63786a refactor checkpoint 2022-06-07 21:31:05 -04:00
John Smith
ef1f5d7b52 refactoring, more config, packaging 2022-05-16 11:52:48 -04:00
John Smith
7458d0d991 work 2022-02-15 13:40:17 -05:00
John Smith
b9862b0016 config change 2022-02-09 09:47:36 -05:00
John Smith
70960fa592 ffi work 2022-02-06 21:18:42 -05:00
John Smith
29b5ec5334 move toward api logging 2022-01-31 10:11:18 -05:00
John Smith
172730a132 lock cargo, fix io 2022-01-29 13:49:27 -05:00
John Smith
205a6a8fd1 clean up veilid state processing 2022-01-18 18:28:22 -05:00
John Smith
1b6864bf22 remove veilid-wasm project, too out of date
refactor state updates and formalize a VeilidState object
work on veilid-flutter api
2022-01-18 12:33:14 -05:00
John Smith
dc9f71a683 fix linux 2022-01-15 18:50:56 -05:00
John Smith
c4b66aad36 debugging 2021-12-14 09:48:33 -05:00
John Smith
43fd315932 logs to client_api 2021-12-10 22:04:38 -05:00
John Smith
c5113623be fixes 2021-12-10 20:14:33 -05:00
John Smith
fba3f5b5f3 Update to NAT detection 2021-12-08 03:09:45 +00:00
John Smith
1c576876ef lints 2021-11-28 20:08:50 -05:00
John Smith
1cecacd8fd lints 2021-11-27 21:31:01 -05:00
John Smith
9e94a6a96f initial import of main veilid core 2021-11-22 11:28:30 -05:00