Skip to content

Loading arduino-cli.yaml from current directory might be unexpected or unsafe #758

Closed
@matthijskooijman

Description

@matthijskooijman

First off: even though I consider this a security problem, I do not think this is very easy to exploit (unnoticed). I've reported this issue tot the Arduino security staff privately first, and we agreed that this would be acceptable for public discussion. Hence this issue.

I noticed (after reading #699 (comment)) that arduino-cli allows loading its arduino-cli.yaml config file from the current directory, or any of the parent directories (e.g. see here and here).

However, I'm a bit worried about the (security) implications of this. It seems that this would make it very easy to mess up arduino-cli when a arduino-cli.yaml file is present in an unexpected location.

From a security standpoint, this means that arduino-cli can never be ran from a untrusted directory, which I think users will not expect.

For example, consider a sketch downloaded from elsewhere. Normally, compiling an untrusted sketch is not problematic, since the files contained in the sketch are only passed to the compiler, not actually executed on the compiling machine. Uploading a sketch with untrusted code to an Arduino can of course be problematic, but Arduinos are usually sufficient sandboxed, and a user can expect that untrusted code will be ran in this case.

Now, consider that this untrusted sketch also contains an arduino-cli.yaml file, that sets up the user directory to a directory inside the sketch. If it then also contains a hardware directory with a custom core, then running arduino-cli compile will execute arbitrary commands from the recipes in the untrusted platform.txt file. These could then do anything, including removing files, installing a backdoor or stealing data.

As for fixing this, here's some thoughts:

  1. You can think of an approach where not all configuration directives will be accepted in these potentially untrusted "project" config files (i.e. divide all config directives into two groups, one needing a trusted config file and the other allowed from any config file). However, this is often fragile, when new options are added or refactored, it is easy to forgot to realize that an option can cause a security problem.

  2. Hence, it might be better to consider an approach where a project config file must be explicitly allowed (e.g. when an arduino-cli.yaml exists in the current directory, arduino-cli should ask the user whether it is trusted, maybe with a short explanation of the risks involved). Then, for each file (maybe along with a checksum), the answer (allow or ignore) should be stored. This is an approach also used by tools like direnv or githooks.

  3. Or maybe disable these project files by default, and enable them in the global arduino-cli.yaml config file.

Note that all of the above suggestions require that the e.g. ~/.arduino15/arduino-cli.yaml global file should always be loaded (either to get values for the trusted-only directives, to store the trusted project config files, or to store the "allow project config" setting). That also opens up the door to loading the global file for defaults, and letting a project config file only override some values, as needed, which reduces the chances of a project config file from accidentally changing settings it does not really need to change.

The essence of this issue has been considered before, which is (I think) one of the reason why per-sketch compilation options were never implemented in the Java IDE (e.g. see arduino/Arduino#421 (comment)).

Metadata

Metadata

Assignees

Labels

topic: codeRelated to content of the project itselftopic: securityRelated to the protection of user datatype: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions