Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
509de1a
Confine writable storage to declared roots while resolving each path …
ambroise-leclerc Nov 5, 2026
6e82ab9
Start each Windows operation from the verified root handle and silenc…
ambroise-leclerc Nov 5, 2026
79f3311
Address the review of #500: Windows rename, macOS ACLs, reserved temp…
ambroise-leclerc Nov 5, 2026
0c9b2b1
Answer the review threads of #500 (#460)
ambroise-leclerc Nov 6, 2026
fc07cb2
Close the listing's directory stream through a function object, as gl…
ambroise-leclerc Nov 6, 2026
bc26c10
Reserve the temporary prefix in every letter case (#460)
ambroise-leclerc Nov 6, 2026
1434ac6
Keep the ACL of a replaced file and keep links away from temporary fi…
ambroise-leclerc Nov 6, 2026
4113ba8
Write the Linux ACL of the replacement test through setxattr, so that…
ambroise-leclerc Nov 6, 2026
efaf752
Take the rights of the replaced file at commit and keep resource erro…
ambroise-leclerc Nov 6, 2026
fdfdd39
Test ENOTSUP and EOPNOTSUPP once where they are the same value, for G…
ambroise-leclerc Nov 6, 2026
95432d6
Keep the temporary file of a replacing write free of inherited ACLs a…
ambroise-leclerc Nov 6, 2026
b9cc0ec
Create the temporary file of a replacing write private, release a com…
ambroise-leclerc Nov 6, 2026
dc95e6d
Parse extended Windows paths from the native string, not root_name() …
ambroise-leclerc Nov 6, 2026
65ddff0
Find the entries of a root at the top of its Windows volume inside it…
ambroise-leclerc Nov 6, 2026
7e36a98
Ignore macOS ACL entries that only pass rights to descendants (#460)
ambroise-leclerc Nov 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

## Unreleased

- Writable storage confined to declared roots (#460, ADR-002 3.0, ADR-020 step 4). `fs::Storage` is the contract of a
writable storage: stable paginated listing (`list(dir, after, limit)`, at most 1000 entries a page), `status`,
`openRead`, `beginWrite(path, createNew | replace)` whose `commit()` renames a temporary file atomically (an uncommitted
writer removes it), `createDirectory`, `remove` and `rename` (never replacing). Failures are `fs::StorageError`, a
`BridgeError` with a `storage.*` code (`notFound`, `linkRefused`, `unsafeDirectory`, `rootMoved`,
`confinementViolated`…) whose message never names the root's host location. `fs::NativeStorage` resolves every path
from the opened root, one component at a time, without following links (`openat(O_NOFOLLOW)` on POSIX, `NtCreateFile`
relative to the parent handle with reparse points refused on Windows; `LinkPolicy::followInside` follows a relative
link that stays inside, POSIX only), checks on every operation that the declared location still designates the root
(`rootMoved`), refuses on POSIX a root, a directory or an ancestor another user could move, by its mode or, on macOS,
its extended ACL (`unsafeDirectory`; `/tmp`
accepted; `RootOptions::shared` lifts the check as a weakened confinement), holds the root and the traversed
directories without `FILE_SHARE_DELETE` on Windows, and detects a directory or a root moved by the same user before a
commit and after every operation (`confinementViolated`). On POSIX a move by the same user or the superuser after the
last check is not prevented. Names starting with `.wf-tmp-`, in any letter case, are reserved to temporary files. A replacing write creates its temporary file private (0600, in a private 0700 directory, without inherited ACL) and its commit gives the new file the group, permission bits and ACL of the file it then replaces (none if it has none), or refuses the replacement; running out of descriptors is not taken for a moved root. `fs::MemoryStorage` is the simulated storage of the tests. `fs::File` reads a
`fs::ByteSource`, the extension point for native handles. `safeRelativePath` now also refuses, on every platform, the
device names Windows reserves (`CON`, `NUL`, `COM1`…, with any extension) and names ending with a dot or a space.
- The bridge supports long strings, homogeneous lists of strings, tuples, typed arrays and bitsets, and typed errors
with application codes. A `cppFunction` callback can return a `webfront::ResultTask<R>` or another sender and answer
when it completes; disconnecting the browser requests cancellation and drops late answers (#456–#459).
Expand Down
6 changes: 6 additions & 0 deletions docs/PROJECT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ are retained for investigation; diagnostics alone do not establish a correction.
Manifest permissions bound only the scripts' `context` API. Only browser packages install;
installation scripts and native add-ons do not run. The [content policy](CONTENT_POLICY.md)
restricts browser origins and navigation but provides neither TLS nor client authentication.
- `fs::NativeStorage` confines writable storage to a declared root while resolving each path, but
on POSIX it cannot prevent the effective user or the superuser from moving a directory out of the
root during an operation: it detects such a move before a commit and after each operation, at
best. Windows prevents those moves while an operation holds its directories; links are always
refused there. A `shared` root lifts the POSIX ownership checks. No service uses the storage yet
(ADR-020). See [ADR-002](adr/ADR-002-systemes-de-fichiers-composables.md).
- A synchronous infinite loop in a spec blocks the page hosting `wf test`; the native test
driver's watchdog terminates stalled runs with failure. Windows file reads beyond 260
characters remain unsupported (#349).
Expand Down
115 changes: 112 additions & 3 deletions docs/adr/ADR-002-systemes-de-fichiers-composables.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion docs/adr/ADR-020-services-systeme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| 1.4 | 2026-11-04 | Proposée, partiellement livrée | Ambroise Leclerc | Livraison de #455 (étape 2) : requêtes partielles `Range` (206, 416, `Accept-Ranges`) pour les fichiers non encodés de taille connue et pour les routes dynamiques (`http::fileReply`, `http::range::select`), `If-Range` sur un `ETag` fort fourni par le fournisseur, plages multiples servies en entier. La liaison à la connexion (#469) reste à faire. | [61a9726](https://github.com/ambroise-leclerc/WebFront/commit/61a9726037edb24cc07601ddc68bcf24b3064d04) |
| 1.5 | 2026-11-04 | Proposée, partiellement livrée | Ambroise Leclerc | Livraison de #469 (étape 2) : `addReadRoute`, `UI::grantRead`, cookie de liaison `wf-client-<port>-<id>` échangé contre un secret à usage unique reçu par le pont, mode transférable borné à 15 minutes, en-têtes de neutralisation, jeton masqué des journaux, transport déclaré (`remoteFileTransport`, `loopbackAttested` vérifié à la configuration). Les tests navigateur passent sous WKWebView ; la qualification sous CEF, WebView2, WebKitGTK et les navigateurs système reste à exécuter. | [ecf17ba](https://github.com/ambroise-leclerc/WebFront/commit/ecf17ba124969037fcdaf4ce4175b9b5f53fe661) |
| 1.6 | 2026-11-05 | Proposée, partiellement livrée | Ambroise Leclerc | Étape 3 (#448) : chaînes longues, listes, erreurs typées et réponses différées du pont ; les services eux-mêmes restent à livrer. | [a51449b](https://github.com/ambroise-leclerc/WebFront/commit/a51449b7bf7796c2e23bddacf11af5ce891335a0), [c817501](https://github.com/ambroise-leclerc/WebFront/commit/c81750191ff0d1e1e1e8f4b42ee5ef49d0d69d64) |
| 1.7 | 2026-11-05 | Proposée, partiellement livrée | Ambroise Leclerc | Livraison de #460 (étape 4) : stockage modifiable sous des racines déclarées (ADR-002 3.0), `fs::Storage`, `fs::NativeStorage` confiné pendant la résolution, contrôle des propriétaires POSIX, handles tenus sans partage de suppression sous Windows, `rootMoved` et `confinementViolated`, `fs::MemoryStorage` simulé. Écarts aux prescriptions : descente composant par composant sous Linux plutôt que `openat2`, points de réanalyse jamais suivis sous Windows (refusés à la traversée et à la lecture, signalés par `status`, supprimés eux-mêmes par `remove`), vérification d'appartenance par le chemin final du handle et renommage par `NtSetInformationFile` sous Windows. #461 reste à faire. | [509de1a](https://github.com/ambroise-leclerc/WebFront/commit/509de1a), branche `460-writable-storage` (PR #500) |

## État et chronologie

Expand Down Expand Up @@ -375,6 +376,8 @@ limites par moteur. #452 est livré dans la version 1.2 (`beforeunload` n'est pa

#469 est livré dans la version 1.5 : `app.addReadRoute(préfixe, gestionnaire)` (sous `/webfront/services/`, hors `bind/`) et `ui.grantRead(route, chemin, ReadOptions)` appliquent les règles ci-dessus. Le jeton est `<identifiant 64 bits>.<secret 256 bits>` placé après le préfixe ; la requête est acceptée si le jeton est connu, non expiré, si la connexion propriétaire est ouverte et si l'un des cookies présentés désigne son client (sauf mode transférable : durée obligatoire de 15 minutes au plus). Un jeton est refusé de la même façon dans tous les cas (`403`, mêmes en-têtes). `WebFront.js` échange le secret reçu par `wfBind.exchange` contre le cookie (`GET /webfront/services/bind/<secret>`, puis `check`) et `webFront.bound` rejette avec une erreur explicite si le navigateur refuse le cookie. Le cookie est `Secure` si l'application déclare `httpsByDeployment` (le navigateur utilise `https://`) ; un tunnel chiffré sous `http://` (`encryptedByDeployment`) n'en reçoit pas, car le navigateur refuserait un cookie `Secure` reçu en HTTP. Un transport non local sans déclaration est refusé à l'émission du jeton et à chaque requête.

#460 est livré dans la version 1.7 (révision 3.0 de l'ADR-002, qui en donne le détail) : `fs::NativeStorage` applique les mesures de la section « Prescriptions » à toute opération (listage paginé, métadonnées, lecture, écriture par temporaire et renommage, création, suppression, renommage), avec les erreurs typées `storage.rootMoved`, `storage.confinementViolated`, `storage.unsafeDirectory`, `storage.linkRefused`… (`fs::StorageError`, une `BridgeError`). Quatre écarts aux prescriptions, sans affaiblir la garantie : sous Linux, la descente composant par composant est toujours employée plutôt qu'`openat2`, puisque chaque répertoire traversé doit être ouvert pour contrôler son propriétaire ; sous Windows, un point de réanalyse n'est jamais suivi (`LinkPolicy::followInside` ne vaut que sous POSIX) : une opération qui le traverserait ou le lirait échoue avec `linkRefused`, tandis que `status` le signale comme lien et que `remove` supprime le point lui-même, sans atteindre sa cible ; sous Windows, l'appartenance du répertoire à la racine se vérifie par le chemin final de son handle, les handles tenus empêchant déjà le déplacement ; sous Windows encore, le renommage passe par `NtSetInformationFile`, car `SetFileInformationByHandle` convertit un nom relatif en chemin absolu, que refuse un renommage relatif au handle d'un dossier (`STATUS_INVALID_PARAMETER`). Les tests Catch2 couvrent le stockage simulé, les sorties par liens (jonctions sous Windows), le remplacement concurrent d'un composant ou du fichier final par des points d'injection, une course répétée (POSIX), les déplacements d'un répertoire ou de la racine pendant la résolution, l'écriture du temporaire et avant la validation, et les propriétaires refusés ou admis (simulés, et `/tmp` réel). Les droits refusés par le système réel ne sont simulés que par `fs::MemoryStorage` : un test qui retire des droits sur disque échoue sous le superutilisateur. Le paquet `@webfront/services` (#461) reste à faire.

Après l'étape 4, le premier service (sélecteur HTML, poignées, import et export côté client) fera l'objet de sa propre
épique ; les dialogues natifs suivront l'étape 5. `PUT`/`POST` ne sont pas des préalables : les écritures passent par
des tableaux typés en morceaux ; leur ajout au serveur, utile aux très gros envois en flux et aux formulaires sans
Expand Down Expand Up @@ -528,7 +531,8 @@ autorisations explicites, backend par connexion).
ouvert, puis `renameat`, `unlinkat`, `mkdirat` relatifs à ce même descripteur. macOS : même descente avec
`O_NOFOLLOW` (ou `O_NOFOLLOW_ANY`), `renameatx_np`. Windows : ouvertures relatives au handle du répertoire
(`NtCreateFile` avec `RootDirectory`), points de réanalyse refusés par composant (`FILE_FLAG_OPEN_REPARSE_POINT`),
renommage par `SetFileInformationByHandle` sur le handle ouvert. Un lien interne à la racine est suivi seulement si la
renommage par `NtSetInformationFile` (`FileRenameInformation`) sur le handle ouvert, relatif au handle du dossier de
destination (`SetFileInformationByHandle` convertit le nom en chemin absolu et ce renommage échoue). Un lien interne à la racine est suivi seulement si la
résolution le confine ; par défaut, les liens sont refusés. Les stockages sans liens (FatFs, LittleFS) se contentent du
contrôle syntaxique.
- **Déplacement d'un répertoire déjà ouvert.** La résolution par descripteur empêche la substitution d'un composant
Expand Down
4 changes: 2 additions & 2 deletions docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ verification evidence remain in [PROJECT_STATUS](../PROJECT_STATUS.md).
| ADR | Decision | Status | Initial creation | Current version |
| --- | --- | --- | --- | --- |
| [ADR-001](ADR-001-coeur-cpp23-header-only.md) | A header-only C++23 core embedded in the application | Accepted | 2020-04-19 | 1.5 — 2026-10-13 |
| [ADR-002](ADR-002-systemes-de-fichiers-composables.md) | An abstract, composable filesystem as the foundation for portability | Accepted | 2023-03-16 | 2.6 — 2026-11-04 |
| [ADR-002](ADR-002-systemes-de-fichiers-composables.md) | An abstract, composable filesystem as the foundation for portability | Accepted | 2023-03-16 | 3.0 — 2026-11-05 |
| [ADR-003](ADR-003-protocole-binaire-et-bornes.md) | A shared, typed and bounded binary protocol | Accepted | 2022-02-06 | 1.19 — 2026-11-05 |
| [ADR-004](ADR-004-appels-asynchrones-et-erreurs.md) | Asynchronous calls with deliberately asymmetric contracts | Accepted | 2022-02-06 | 2.6 — 2026-11-05 |
| [ADR-005](ADR-005-evolution-reseau-asio-stdnet.md) | From standalone ASIO to stdnet: anticipating standard networking without blocking progress | Accepted through 3.1; 3.2 proposed | 2022-01-21 | 3.2 — 2026-10-26 |
Expand All @@ -60,7 +60,7 @@ verification evidence remain in [PROJECT_STATUS](../PROJECT_STATUS.md).
| [ADR-017](ADR-017-acces-direct-aux-frontends.md) | Direct access to embedded frontends, with HTML kept normative | Proposed | 2026-10-24 | 1.1 — 2026-10-25 |
| [ADR-018](ADR-018-acces-au-dom.md) | DOM access from C++ through a bounded mutation stream, without contesting the DOM of UI libraries | Proposed, partially superseded, partially delivered | 2026-10-26 | 1.5 — 2026-10-30 |
| [ADR-019](ADR-019-developpement-automatisable-et-agents.md) | Automating the developer environment through shared operations and an optional local MCP adapter | Accepted | 2026-10-28 | 1.2 — 2026-10-29 |
| [ADR-020](ADR-020-services-systeme.md) | System services (files, clipboard, shell, notifications…) through optional C++ portals with per-connection backends, granting handles rather than paths | Proposed | 2026-10-31 | 1.6 — 2026-11-05 |
| [ADR-020](ADR-020-services-systeme.md) | System services (files, clipboard, shell, notifications…) through optional C++ portals with per-connection backends, granting handles rather than paths | Proposed | 2026-10-31 | 1.7 — 2026-11-05 |
| [ADR-021](ADR-021-publication-de-l-environnement-developpeur.md) | Simplifying the publication of the developer environment: automate the release, keep pinned hashes, no dedicated server | Accepted (domain delivered; phase 1 to implement) | 2026-11-02 | 1.0 — 2026-11-02 |

Numbering follows the reading topics; milestones and individual file histories provide
Expand Down
41 changes: 38 additions & 3 deletions include/webfront/system/FileSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include <fstream>
#include <filesystem>
#include <ios>
#include <memory>
#include <optional>
#include <span>
#include <stdexcept>
#include <string>
#include <string_view>

Expand All @@ -34,22 +36,43 @@ concept EncodedData = IsData<T> && HasEncoding<T>;
template<typename T>
concept RawData = IsData<T>;

/// @brief The bytes of a file a provider or a storage reads through its own handle: a descriptor opened relative to a
/// storage root (fs::NativeStorage), and later the handles a platform grants instead of a path (an Android
/// `content://` URI, a macOS security-scoped URL), which a provider wraps without WebFront knowing them.
class ByteSource {
public:
virtual ~ByteSource() = default;
/// Reads up to `buffer.size()` bytes; fewer only at the end of the content.
virtual std::size_t read(std::span<char> buffer) = 0;
/// The number of bytes left from the position the source had when the File was built, when known.
[[nodiscard]] virtual std::optional<std::uint64_t> size() const = 0;
/// Positions the next read at `offset` bytes from that original position; false when the source cannot seek.
[[nodiscard]] virtual bool seek(std::uint64_t offset) = 0;
};

class File {
enum class FileType { nativeFStream, staticData };
enum class FileType { nativeFStream, staticData, byteSource };
public:
File(EncodedData auto t) : File(decltype(t)::data, decltype(t)::dataSize, decltype(t)::encoding) {}
File(RawData auto t) : File(decltype(t)::data, decltype(t)::dataSize) {}
File(std::span<const uint64_t> input, size_t fileSize, std::string_view contentEncoding = "")
: fileType{FileType::staticData}, data(input), size(fileSize), eofBit(fileSize==0), encoding(contentEncoding) {}
File(std::ifstream ifstream) : fileType{FileType::nativeFStream}, fstream{std::move(ifstream)} { measureStream(); }
/// A file read through a provider's own handle (see ByteSource).
explicit File(std::unique_ptr<ByteSource> byteSource) : fileType{FileType::byteSource}, source{std::move(byteSource)} {
if (!source) throw std::invalid_argument("A File needs a byte source");
}

[[nodiscard]] bool isEncoded() const { return !encoding.empty(); }
[[nodiscard]] std::string_view getEncoding() const { return encoding; }
[[nodiscard]] bool eof() const { return eofBit; }

/// The number of bytes this file yields, when known before reading it (always for embedded data, and for a
/// native file whose stream can seek). A server uses it to announce a length and stream the file in chunks.
[[nodiscard]] std::optional<std::uint64_t> knownSize() const { return fileType == FileType::staticData ? std::optional<std::uint64_t>{size} : streamSize; }
[[nodiscard]] std::optional<std::uint64_t> knownSize() const {
if (fileType == FileType::byteSource) return source->size();
return fileType == FileType::staticData ? std::optional<std::uint64_t>{size} : streamSize;
}

/// A strong entity tag (RFC 9110 §8.8.3) for the bytes this file yields, when its provider can guarantee one.
/// WebFront derives none from a pathname, a size or a modification time: those can describe another version than
Expand All @@ -70,6 +93,10 @@ class File {
eofBit = readIndex == size;
return true;
}
if (fileType == FileType::byteSource) {
eofBit = false;
return source->seek(offset);
}
if (!streamSize || !fstream.is_open()) return false;
const auto target = std::min(offset, *streamSize);
fstream.clear();
Expand All @@ -83,7 +110,8 @@ class File {
// @return bytes read
size_t read(std::span<char> buffer) {
if (fileType == FileType::staticData) return readData(buffer);
else return readFStream(buffer);
if (fileType == FileType::byteSource) return readSource(buffer);
return readFStream(buffer);
}

private:
Expand All @@ -96,6 +124,13 @@ class File {
bool eofBit{false};
const std::string encoding{};
std::ifstream fstream;
std::unique_ptr<ByteSource> source;

size_t readSource(std::span<char> buffer) {
const auto count = source->read(buffer);
if (count < buffer.size()) eofBit = true;
return count;
}

// The generated headers pack the bytes into big-endian 64-bit words. Each byte is taken from
// its word by position, so a read may stop in the middle of a word.
Expand Down
Loading
Loading