feat: sparse fieldset selection with explicit allowlisting - #391
Open
LuisD-Dev wants to merge 2 commits into
Open
feat: sparse fieldset selection with explicit allowlisting#391LuisD-Dev wants to merge 2 commits into
LuisD-Dev wants to merge 2 commits into
Conversation
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.
closes #337
Sparse Fieldset Selection with Explicit Allowlisting
Problem
REST endpoints that support
?fields=a,b,csparse fieldsets face twodistinct risks that are easy to conflate:
of a query. Solved with parameterization.
structured, never-intended-to-be-exposed data. This is not solvable
with escaping, since the database has no concept of "this column
exists but clients shouldn't be able to ask for it by name." It's only
solvable with an explicit allowlist.
This PR addresses risk #2 by introducing a per-domain allowlist that is
deliberately separate from — and a strict subset of — each struct's full
field set.
What's included
backend/src/field_selection/mod.rs— public API: error type,parse_fields, allowlist lookupallowlist.rs— explicit per-domain allowlists (snapshots,aggregates), each mapped from real structs already in the codebase(
NormalizedSnapshotSubmitted,OffChainAggregate). Each excludedfield is documented inline with the reason it's excluded (internal
reconciliation state, operator privacy, etc.)
parse.rs— parses thefieldsquery param, rejects anynon-allowlisted field via a typed
FieldSelectionError, neversilently drops or ignores unknown fields
README.md— explains why this module exists ahead of an HTTPserver, and how to wire it in once one exists
backend/tests/non_allowlisted_field_test.rs— requests a real,known internal field that exists on the struct but was deliberately
excluded from the allowlist; asserts rejection
backend/tests/injection_shaped_field_test.rs— requests a fieldname shaped like
"; DROP TABLE users; --"; asserts it's rejected atthe allowlist lookup (
HashMap::get→None), not merely neutralizedby escaping — there is no SQL layer in this codebase yet, so this test
demonstrates the rejection path is name-validation, not sanitization
backend/src/lib.rs— registers the new module (+2 lines)Design notes
main.rs,no web framework in
Cargo.toml). The module is intentionallytransport-agnostic — pure parsing + allowlist logic, no dependency on
axum/actix/etc. — so it can be wired into whichever HTTP layer gets
built later without rework.
HashMaplookupkey. It is never interpolated into any string that could reach a query
or output layer.
#[derive]or reflection — adding a new field to a Rust struct doesnot automatically expose it via this module.
Testing
cargo build --all— clean, no new warningscargo test field_selection— passcargo test --test non_allowlisted_field_test— passcargo test --test injection_shaped_field_test— passOut of scope
The
README.mddocuments the intended integration point for whena server exists.
docs/contains pre-existing case-collisionduplicates (e.g.
LICENSE.md/license.md) that cause noisy diffson case-insensitive filesystems (Windows/macOS). Not touched here;
worth a separate cleanup issue.