FAQ - Help and questions

Is safe Rust enough to make my application secure?

#security#basics#memory-safetypublished 0 replies0 views
ReplyWatch
Share
Hacker NewsRedditLinkedInE-mail

Short answer

No. Safe Rust rules out memory corruption such as buffer overflows, use after free and data races, which removes a large class of bugs. It does not stop logic mistakes, injection, weak authentication, leaked secrets or vulnerable dependencies. Those need design, review and tooling, covered in this series.

Frequently asked question, written and answered by the Ruststudio team. Replies are open: corrections are welcome.

#1

Answer#

Rust's guarantee is about memory: code written without unsafe cannot read or write memory it does not own, cannot use a value after it was freed, and cannot have two threads change the same data without synchronisation. That removes a big source of serious bugs. It says nothing about whether your program does the right thing with the data it handles.

ProblemDoes safe Rust prevent it?Where to look
Buffer overflow, use after free, data raceYes (outside unsafe)The Rust Book, ownership chapters
SQL injection, command injectionNo: a query is just a stringThe thread on parameterised queries
Path traversal in file names from usersNoThe thread on path traversal
Weak or missing authentication, broken sessionsNoThe password, session and CSRF threads
Secrets in source code or logsNoThe threads on secrets and logs
A vulnerable or malicious dependencyNoThe cargo audit, cargo deny and supply-chain threads
Integer overflow giving a wrong resultPartly: it panics in debug builds and wraps in release buildsThe thread on integer overflow
A panic that an attacker can trigger repeatedlyNo: it is memory safe, but it is still an outageThe thread on panics and untrusted data
Bugs inside unsafe blocks, or in C libraries you callNo: the compiler trusts you thereThe threads on reviewing unsafe

The point of the table is the middle column. Rust moves the work: you spend less time on memory errors and can spend it on the rows below them.

How to do it#

  1. Treat everything that crosses a trust boundary (network, files, environment, command line, other processes) as hostile until it is parsed and checked.
  2. Keep secrets out of source and logs, and hash passwords with a memory-hard algorithm.
  3. Run cargo audit and cargo deny in CI so known-vulnerable dependencies are caught.
  4. Keep unsafe small, documented and reviewed.
  5. Run the service with the least privilege it needs.

Common mistakes#

  • Assuming "it is written in Rust" is a security review. A Rust service can still have an open admin page or a guessable token.
  • Using unsafe casually for speed without measuring. The memory guarantee ends exactly there.
  • Forgetting that dependencies run with your program's permissions, and some of their code runs at build time.

Can a Rust program still crash from untrusted input?#

Yes. Indexing out of range, unwrap on None and arithmetic overflow in debug builds all panic. That is memory safe, but an attacker who can trigger it repeatedly can take the service down.

Does unsafe turn the safety checks off everywhere?#

No. It allows a small set of extra operations (such as dereferencing a raw pointer). The borrow checker and type checker keep working for everything else in the block. The responsibility for those few operations moves to you.

Sources#

    QuoteReply
    Share
    Hacker NewsRedditLinkedInE-mail

    No replies yet