Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit Trillium #80

Open
8573 opened this issue Oct 20, 2022 · 4 comments
Open

Audit Trillium #80

8573 opened this issue Oct 20, 2022 · 4 comments

Comments

@8573
Copy link
Contributor

8573 commented Oct 20, 2022

Trillium "is a composable toolkit for building web applications". It is not popular (727 downloads/month), but it has very little unsafe in its own code: just two calls to std::net::TcpListener::from_raw_fd, with the file descriptor number taken from an environment variable.

Edited to add: Trillium is mostly under #[forbid(unsafe_code)].

@Shnatsel
Copy link
Member

Shnatsel commented Oct 20, 2022

I believe OwnedFd can be used to avoid unsafe in this case, as detailed here. It's a very recent addition, but it is stable.

@8573
Copy link
Contributor Author

8573 commented Oct 26, 2022

I note that the "Safety" documentation for from_raw_fd says

The fd passed in must be a valid and open file descriptor.

As far as I saw, Trillium does not check that the file descriptor numbers refer to valid, open file descriptors before calling from_raw_fd. Is that unsound?

@Shnatsel
Copy link
Member

That's unsound, yes. But It's quite strange to read a file descriptor number of all the things from an environment variable; it would be quite difficult to specify what file you wish to operate on. This suggests that it may be a testing facility or something of the sort. In any case, this does warrant a closer look.

@8573
Copy link
Contributor Author

8573 commented Oct 27, 2022

It's quite strange to read a file descriptor number of all the things from an environment variable

I think I found the explanation:

Trillium seeks to abide by a 12 factor approach to configuration, accepting configuration from the environment wherever possible. [...] In addition to accepting the HOST and PORT configuration from the environment, on cfg(unix) systems, trillium will also pick up a LISTEN_FD environment variable for use with catflap/systemfd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants