Skip to content

Commit a120918

Browse files
committed
initial commit
0 parents  commit a120918

File tree

10 files changed

+559
-0
lines changed

10 files changed

+559
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
book/

LICENCE.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# OPEN LICENCE 2.0/LICENCE OUVERTE 2.0
2+
3+
## “Reuse” of the “Information” covered by this licence
4+
5+
The “Grantor” grants the “Reuser” the free, non-exclusive right to “Reuse” the “Information” subject of this licence, for commercial or non-commercial purposes, worldwide and for an unlimited period, in accordance with the conditions stated below.
6+
7+
**The “Reuser” is free to reuse the “Information”:**
8+
9+
- To reproduce it, copy it.
10+
- To adapt, modify, retrieve and transform it in order to create “derived information”, products and services.
11+
- To share, disseminate, redistribute, publish and transmit it.
12+
- To exploit it for commercial purposes, e.g., by combining it with other information, or by including it in his/her own product or application.
13+
14+
**Subject to:**
15+
16+
- An acknowledgement of the authorship of the “Information”: its source (at least, the name of the “Grantor”) and the date of the most recent update of the reused “Information”. Specifically, the “Reuser” may satisfy this condition by pointing, via a hypertext link, to the source of “the Information” and so supplying an actual acknowledgement of its authorship.
17+
18+
**For example:**
19+
20+
> “Ministry of xxx—Original data downloaded from `http://www.data.gouv.fr/fr/datasets/xxx/`, updated on 14 February 2017”.
21+
22+
This acknowledgement of authorship does not confer any official status on the “Reuse” of the “Information”, and must not suggest any sort of recognition or endorsement on the part of the “Grantor”, or any other public entity, of the “Reuser” or of their “Reuse”.
23+
24+
## Personal data
25+
26+
The “Information” made available may contain “Personal data” that may be subject to “Reuse”. If this is the case, the “Grantor” informs the “Reuser” about its existence. The “Information” may be freely reused, within the rights granted by this licence, subject to compliance with the legal framework relating to personal data protection.
27+
28+
## Intellectual property rights
29+
30+
It is guaranteed to The “Reuser” that potential “Intellectual property rights” held by third parties or by the “Grantor” on “Information” do not interfere with the rights granted by this licence.
31+
32+
When the “Grantor” holds transferable “Intellectual property rights” on the “Information”, he/she assigns these to the “Reuser” on a non-exclusive basis, free of charge, worldwide, for the entire duration of the “Intellectual property rights”, and the “Reuser” is free to use the “Information” for any purpose that complies with the rights and conditions defined in this licence.
33+
34+
## Liability
35+
36+
The “Information” is made available as it is produced or received by the “Grantor”, without any other express or tacit guarantee than those set out in this licence. The “Grantor” does not guarantee the absence of errors or inaccuracies in the “Information”, nor a continuous supply of the “Information”. He/she cannot be held responsible for any loss, prejudice or damage of any kind caused to third parties as a result of the “Reuse”.
37+
38+
The “Reuser” is solely responsible for the “Reuse” of the “Information”. This “Reuse” must not mislead third parties as to the contents of the “Information”, its source or its date of update.
39+
40+
## Applicable legislation
41+
42+
This licence is governed by French law.
43+
44+
### Compatibility of this licence
45+
46+
This licence has been designed to be compatible with any free licence that at least requires an acknowledgement of authorship, and specifically with the previous version of this licence as well as with the following licences: United Kingdom’s “Open Government Licence” (OGL), Creative Commons’ “Creative Commons Attribution” (CC-BY) and Open Knowledge Foundation’s “Open Data Commons Attribution” (ODC-BY).
47+
48+
## Definitions
49+
50+
Within the meaning of this licence, are to be considered as :
51+
52+
- The “Grantor”: any person granting the right to “Reuse” “Information” under the rights and conditions set out in this licence.
53+
- The “Information”:
54+
- any public information contained in documents disclosed or published by any administration referred to in the first paragraph of Article L. 300-2 of the code des relations entre le public et l’administration (CRPA),
55+
- any information made available by any person under the terms and conditions of this licence.
56+
- The “Reuse”: the use of the “Information” for other purposes than those for which it was produced or received.
57+
- The“Reuser”: any person reusing the “Information” in accordance with the conditions of this licence.
58+
- “Personal data”: any information relating to an identified or identifiable natural person who may be identified directly or indirectly. Its “Reuse” is conditional on the respect of the existing legal framework.
59+
- “Derived information”: any new data or information created directly from the “Information” or from a combination of the “Information” and other data or information not subject to this licence.
60+
- “Intellectual property rights”: all rights identified as such under the code de la propriété intellectuelle (including copyright, rights related to copyright, sui generis rights of database producers, etc.).
61+
62+
## About this licence
63+
64+
This licence is intended to be used by administrations for the reuse of their public information. It can also be used by any individual wishing to supply “Information” under the conditions defined in this licence.
65+
66+
France has a comprehensive legal framework aiming at the spontaneous dissemination by the administrations of their public information in order to ensure the widest possible reuse of this information.
67+
68+
The right to “Reuse” the administrations’ “Information” is governed by the code des relations entre le public et l’administration (CRPA).
69+
70+
This licence facilitates the unrestricted and free of charge reuse of public information and is one of the licences which can be used by the administration pursuant to the decree issued under article L. 323-2 of the CRPA.
71+
72+
Under the Prime Minister’s authority, the Etalab mission is mandated to open up the maximum amount of data held by State administrations and public institutions. Etalab has drawn up the Open Licence to facilitate the unrestricted and free of charge reuse of public information, as defined by article L. 321-1 of the CRPA.
73+
74+
This licence is version 2.0 of the Open Licence.
75+
76+
Etalab reserves the right to propose new versions of the Open Licence. Nevertheless, “Reusers” may continue to reuse information obtained under this licence should they so wish.

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Guide to develop secure applications with Rust
2+
3+
## Objectives
4+
5+
The object of this document is to provide hints and recommendations for secure
6+
applications development using the Rust programming language.
7+
8+
It is not intended to be a course on how to write Rust programs, there are
9+
already plenty of good learning resources for this purpose (see the *External
10+
references* section below). The purpose is rather to guide the programmer and to
11+
inform him about certain pitfalls, especially in case he is involved in the
12+
development of applications with strong security requirements. These
13+
recommendations form a complement to the good level of trust the Rust language
14+
already provides. That said, recalls are sometimes necessary for clarity, and
15+
the experienced Rust programmer may rely solely on *Recommendation* or *Warning*
16+
inserts.
17+
18+
It is currently an ongoing version and all contributions are welcome.
19+
20+
## Reading the guide online
21+
22+
[Summary](./src/SUMMARY.md)
23+
24+
## Building the guide
25+
26+
```
27+
$ cargo install mdbook
28+
$ mdbook serve -o
29+
```
30+
31+
## Contributions
32+
33+
Feel free to create pull requests to suggest recommendations or modifications,
34+
or to submit an issue to start discussions.
35+
36+
## Licence
37+
38+
This document is published under the [Open Licence 2.0](LICENCE.md).
39+
40+
## External references
41+
42+
- [The Rust programming language](https://www.rust-lang.org)
43+
- [The Rust book](https://doc.rust-lang.org/stable/book)
44+
- [About Rust editions](https://rust-lang-nursery.github.io/edition-guide)
45+
- [Rust API guidelines](https://rust-lang-nursery.github.io/api-guidelines)
46+
47+
One can also find an up-to-date list of various book resources about Rust and
48+
associated tools in the [Rust documentation main
49+
page](https://doc.rust-lang.org).

src/01_introduction.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Introduction
2+
3+
[Rust](https://www.rust-lang.org) is a multi-paradigm language with a focus on
4+
memory safety.
5+
6+
It aims to be systems programming oriented, allowing fine-grained memory
7+
management without garbage collection but also without tedious and error-prone
8+
manual memory allocations and deallocations. It achieves this goal by means of
9+
its ownership system (mostly related to variable aliasing). At any point of a
10+
Rust program, the compiler tracks how many variables refer to a given data, and
11+
enforces a set of rules which enable automatic memory management, memory safety
12+
and data-race free programs.
13+
14+
The language also focuses on performance, with powerful compilation
15+
optimizations and language constructs that allows writing zero-cost abstraction
16+
code.
17+
18+
Moreover, the Rust language provides some high-level programming features.
19+
Thanks to higher-order functions, closures, iterators, etc., it allows writing
20+
program parts in the same vein as in functional programming languages.
21+
Besides, static typing discipline, type inference, and ad hoc polymorphism (in
22+
the form of traits) are other ways Rust provides to build libraries and programs
23+
in a safe manner.
24+
25+
Nevertheless, due to its versatility, the language possibly offers some
26+
constructions that, if not used properly, can introduce security problems,
27+
either by or by making code misinterpreted by the programmer or a reviewer. In
28+
addition, as for every tool in the compilation or software verification field,
29+
the tools used to develop, compile and execute programs can expose certain
30+
features or configurations that, if misused, may lead to vulnerabilities.
31+
32+
Thus, the object of this document is to compile hints and recommendations to
33+
stay in a safe zone for secure applications development while taking advantage
34+
of the range of possibilities Rust language can offer.
35+
36+
## Target Audience
37+
38+
The guide intents to group recommendations that should be applied for
39+
application development with strong security level requirements. Anyway, it can
40+
be followed by everyone who wants to ensure that guarantees offered by the Rust
41+
platform are not invalidated due to unsafe, misleading or unclear feature usage.
42+
43+
It is not intended to be a course on how to write Rust programs, there are
44+
already plenty of good learning resources for this purpose
45+
(see for instance the
46+
[Rust documentation main page](https://doc.rust-lang.org)).
47+
The purpose is rather to guide the programmer and to inform him about certain
48+
pitfalls. These recommendations form a complement to the good level of trust
49+
the Rust language already provides. That said, recalls are sometimes necessary
50+
for clarity, and the experienced Rust programmer may rely solely on
51+
*Recommendation* or *Warning* inserts.
52+
53+
## Structure of the Document
54+
55+
The aim with the structure of this document is to consider separately different
56+
phases of a typical (and simplified) development process. Firstly, we provide
57+
some advices for using tools of the Rust ecosystem to how to take advantage
58+
of them for secure development. A second chapter focuses on precautions to
59+
take when choosing and using external libraries. Then, recommendations about
60+
the Rust language constructs are exposed. Finally, we introduce advices for
61+
writing tests for a project in Rust, and for using Rust fuzzing tools.
62+
A summary of recommendations presented throughout the document is listed at the
63+
end of this guide.

src/02_devenv.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Development Environment
2+
3+
## `rustup`
4+
5+
`rustup` is the Rust toolchain installer. Among other things, it enables
6+
switching between different flavors of the toolchain (stable, beta, nightly),
7+
managing additional components installation and keeping them up to date.
8+
9+
> ### Warning:
10+
> From a security perspective, `rustup` does perform all downloads over HTTPS,
11+
> but doesn’t validate signatures of downloads. Protection against downgrade
12+
> attacks, certificate pinning, validation of signatures are works that are
13+
> currently in progress. In some cases, it may be preferable to opt for
14+
> an alternative installation method listed in the *Install* section of the
15+
> official rust website.
16+
17+
### Rust Editions
18+
19+
Several flavors, called *editions*, of the Rust language coexist.
20+
The concept of editions has been introduced to clarify new features
21+
implementation and to make them incremental. But as stated in the
22+
[Edition Guide](https://rust-lang-nursery.github.io/edition-guide/editions/index.html),
23+
this doesn’t mean that new features and improvements will be shipped on
24+
the last edition only.
25+
26+
However, some editions could bring new keywords and language constructs.
27+
Recommendations for secure applications development then remain closely
28+
linked to features that are used in such applications rather than the actual
29+
edition that is declared in it.
30+
In the rest of this guide, best effort will be made to highlight constructions
31+
and language features that are specific to a particular Rust edition.
32+
33+
> ### Note:
34+
> No specific edition is recommended, as long as users follow recommendations
35+
> that are expressed in relation to features offered by edition that has been
36+
> chosen.
37+
38+
### Stable, nightly and beta toolchains
39+
40+
Orthogonally to editions that allows one to select a flavor (a set of features)
41+
of the Rust language, the Rust toolchain is provided in three different
42+
versions, called *release channels*:
43+
44+
- *nightly* releases are created once a day,
45+
- *nightly* releases are promoted every six weeks to *beta* releases,
46+
- *beta* releases are promoted every six weeks to *stable* releases.
47+
48+
When playing with different toolchains, it is important to check not only what
49+
the default toolchain is, but also if overrides are currently set for some
50+
directories.
51+
52+
```shell
53+
$ pwd
54+
/tmp/foo
55+
$ rustup toolchain list
56+
stable-x86_64-unknown-linux-gnu (default)
57+
beta-x86_64-unknown-linux-gnu
58+
nightly-x86_64-unknown-linux-gnu
59+
$ rustup override list
60+
/tmp/foo nightly-x86_64-unknown-linux-gnu
61+
$
62+
```
63+
64+
> ### Recommendation:
65+
> In general, development of a secure application should be done using a
66+
> fully stable toolchain, for limiting potential compiler, runtime or tool
67+
> bugs.
68+
69+
When using a specific cargo subcommand that requires a nightly component,
70+
it is preferable to run it by switching the toolchain only locally, instead
71+
of explicitly switching the complete toolchain. For example, to run the
72+
(nightly) latest `rustfmt`:
73+
74+
```shell
75+
$ rustup toolchain list
76+
stable-x86_64-unknown-linux-gnu (default)
77+
beta-x86_64-unknown-linux-gnu
78+
nightly-x86_64-unknown-linux-gnu
79+
$ rustup run nightly cargo fmt
80+
$ # or
81+
$ cargo +nightly fmt
82+
$
83+
```
84+
85+
## `cargo`
86+
87+
Once `rustup` has been used to set up the appropriate Rust toolchain, the
88+
tool `cargo` has been made available. It’s the Rust package manager, that
89+
provides ways to structure and build projects, managing on its own dependencies
90+
download among other tasks. It’s also a front-end to run complementary tools such
91+
as those that are described below, in the form of sub-commands.
92+
93+
<mark>TODO</mark>: identify unsafe features and risky environment variables.
94+
95+
### clippy
96+
97+
Clippy is a tool that provides and checks many lints (bugs, styling, performance
98+
issues, etc.). Since the stable toolchain has reached version 1.29, `clippy` can
99+
be used within the stable rustup environment. It is also recommended
100+
to install `clippy` as a component (`rustup component add clippy`) in the
101+
stable toolchain instead of installing it as a project dependency.
102+
103+
The tool comes with some lint categories regarding the kind of issue it aims to
104+
detect. The warnings should be re-checked by the programmer before committing
105+
the fix that is suggested by `clippy`, especially in the case of lints of the
106+
category `clippy::nursery` since those hints are still under development.
107+
108+
> ### Recommendation:
109+
> The tool `clippy` must be used at various times during a secure application
110+
> development process.
111+
112+
### rustfmt
113+
114+
<mark>TODO</mark>: introduce the rustfmt tool and recommend its use.
115+
116+
### Others
117+
118+
There exist other useful tools or cargo subcommands for enforcing program
119+
security whether by searching for specific code patterns or by providing
120+
convenient commands for testing or fuzzing. They are discussed in the following
121+
chapters, according to their goals.

src/03_libraries.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Libraries
2+
3+
In addition to a standard library, Rust provides an easy way to import libraries
4+
in a project, thanks to `cargo`. The libraries, known as *crates* in the Rust
5+
ecosystem, are imported from the open-source components central repository
6+
[crates.io](https://crates.io).
7+
8+
It should be noticed that the quality (in terms of security, performances,
9+
readability, etc.) of the published crates is very variable. Moreover, their
10+
maintenance can be irregular or interrupted. The usage of each component from
11+
this repository should be justified, and the developer should validate the
12+
correct application of rules from the current guide in its code. Several tools
13+
can aid in that task.
14+
15+
## cargo-outdated
16+
17+
Cargo-outdated tool allows one to easily manage dependencies versions.
18+
19+
For a given crate, it lists current dependencies versions (using its
20+
`Cargo.toml`), and checks latest compatible version and also latest general
21+
version.
22+
23+
> ### Recommendation:
24+
> <mark>TODO</mark>: run cargo-outdated to check dependencies status
25+
26+
## Unsafe code in libraries
27+
28+
<mark>TODO</mark>: `unsafe` blocks are discussed in the following chapter.
29+
One needs to ensure that this kind of block is not misused in project
30+
dependencies.
31+
32+
> ### Recommendation:
33+
> <mark>TODO</mark>: check that no `unsafe` blocks appear in the imported
34+
> dependencies (with a tool?).

0 commit comments

Comments
 (0)