Centralize file access validation with FileAccess capability token#1327
Merged
Conversation
lovasoa
added a commit
that referenced
this pull request
Jun 12, 2026
Each built-in `sqlpage.*` function is now a plain `async fn` in its own file under `sqlpage_functions/functions/`, with an ordinary Rust signature and no marker comments or macros inside it. Registration is automatic: `build.rs` lists the files in `functions/` into a `sqlpage_functions!` call (the only generated code, one line per function), and that macro declares the modules and builds the `SqlPageFunctionName` enum the SQL engine dispatches on. There is no marker-comment parsing and no per-argument codegen. Argument extraction, dispatch and return-value conversion are ordinary generic code in function_traits.rs (`Extract`, `Handler`, `IntoCowResult`), using the same `Fn`-arity trick axum uses for handlers, so a function's argument and return types are read straight from its signature. Also folds in main's FileAccess centralization (#1327) for the file-reading functions. Verified: `cargo test` passes (148 lib + 70 integration tests, including run_all_sql_test_files, the hmac webhook tests, the upload tests and test_file_upload_through_runsql which exercises the &mut DbConn path). `cargo clippy` and `cargo fmt --check` are clean.
lovasoa
added a commit
that referenced
this pull request
Jun 12, 2026
* refactor: split SQLPage functions into one module each Each built-in `sqlpage.*` function is now a plain `async fn` in its own file under `sqlpage_functions/functions/`, with an ordinary Rust signature and no marker comments or macros inside it. Registration is automatic: `build.rs` lists the files in `functions/` into a `sqlpage_functions!` call (the only generated code, one line per function), and that macro declares the modules and builds the `SqlPageFunctionName` enum the SQL engine dispatches on. There is no marker-comment parsing and no per-argument codegen. Argument extraction, dispatch and return-value conversion are ordinary generic code in function_traits.rs (`Extract`, `Handler`, `IntoCowResult`), using the same `Fn`-arity trick axum uses for handlers, so a function's argument and return types are read straight from its signature. Also folds in main's FileAccess centralization (#1327) for the file-reading functions. Verified: `cargo test` passes (148 lib + 70 integration tests, including run_all_sql_test_files, the hmac webhook tests, the upload tests and test_file_upload_through_runsql which exercises the &mut DbConn path). `cargo clippy` and `cargo fmt --check` are clean. * less magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
priviledgedboolean through several APIs, creating a maintenance and security footgun.Description
Copycapability tokenFileAccess<'a>withFileAccess::unprivileged(path)that runs the guard at construction andFileAccess::privileged(path)for trusted callers, and make the validator module-private.FileSystemAPIs to acceptFileAccessinstead of aprivilegedboolean, makesafe_local_pathreturn an infalliblePathBuf, and derive the path viaaccess.path().FileCacheand theFileStore::containssignature to acceptFileAccess, changegetto takeFileAccess, and remove ad-hoc pre-checks so the guard is enforced once at token creation.FileAccess::unprivileged(...)and templates,run_sql, and internalread_filebuildFileAccess::privileged(...); also let-bind derived candidate paths beforeawaitpoints where needed.Testing
cargo fmt --allwhich completed successfully.cargo +1.95.0 clippy --all-targets --all-features -- -D warningswhich succeeded (linting performed with the newer toolchain).cargo +1.95.0 testand all tests passed (147 unit tests and 70 integration tests reported).libsqlite3-sys) due to an unstablecfg_selectusage, so linting and tests were executed with the installed Rust 1.95.0 toolchain as recorded in the PR notes.Codex Task