Repository navigation
fix(views): enforce authz, row scoping and close query oracles - #590
Merged
Merged
Conversation
yevheniidehtiar
force-pushed
the
fix/v058-authz-hardening
branch
from
October 9, 2026 15:24
f97748f to
5a58792
Compare
added 4 commits
October 9, 2026 23:54
…, file and choices handlers (st-v058-byoa-10) - request-scoped queryset filter held in a ContextVar (core/adapters.queryset_scope); every DynamicModelView handler runs inside it - model + object permission checks on inline edit/save, inline add-row, update form, delete-file, upload and single actions - delete-file/upload accept file fields only; storage paths resolved through core/storage_paths.resolve_storage_path (no escape from the storage root) - inline formsets reject child pks not owned by the parent (404 before any write) and enforce the inline model's add/change/delete permissions - choices endpoint requires view on the target model
…d choices (st-v058-byoa-53) - core/sensitive.is_sensitive + AdminOptions.sensitive_fields overrides; User.password_hash marked - inferred search/columns/filters, adapter fallback search and choices q search skip sensitive fields - URL filters whitelisted to list_filter; sort_by whitelisted to displayed non-sensitive columns (unknown -> default sort, 200) - detail view hides sensitive fields; forms treat them as write-only (empty keeps stored value) - choices endpoint forwards only declared cascade keys and applies the target admin get_queryset - changelog security note
…byoa-10) - Gate every disclosure of related rows on view_<target> through one helper: choices endpoint, list-page relation filters and create/edit relation widgets (only the selected key is kept, labelled Model (pk)). - Unregistered inline models and relation targets fall back to the parent or source permission, since no permission row can exist for them. - Uploads ignore the client path, never overwrite a stored file, stay inside the storage root and return a relative name. - Document the inline_child_pks requirement for custom adapters.
…v058-byoa-53) - Label related rows with a sensitive-aware display name, never SQLModel's default __str__, in choices, FK filters, relation widgets and list cells. - Apply each model admin's sensitive_fields overrides inside adapters (fallback search, choices q, cascade guard) via a request-scoped resolver; an explicit empty search_fields disables search. - Inline rows treat sensitive child fields as write-only. - Limit the name heuristic to text fields; marked non-text fields are left out of the edit form and keep their stored value. - Refuse FK writes to rows the target admin's get_queryset hides. - Document the SQLModel-compatible sensitive marker.
yevheniidehtiar
force-pushed
the
fix/v058-authz-hardening
branch
from
October 9, 2026 21:59
5a58792 to
0dd8a35
Compare
dodjer88
approved these changes
Oct 9, 2026
dodjer88
approved these changes
Oct 9, 2026
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.
Why
Several admin handlers had live security gaps (Owner decision 4: standalone
fix(views)work, not gated by the SDD):get_querysetrow scoping lived on the shared adapter instance, so it was skipped on several handlers and could leak between concurrent requests.DELETE /{model}/{id}/file/{field}could delete any server file, through a text column or a path outside the storage root.password_hash, and the detail and edit pages showed it directly.Spec:
docs/specs/bring-your-own-app.mdsections B.6, A.3, A.6, D.2, D.3 and Owner decision 7. Stories: st-v058-byoa-10 and st-v058-byoa-53.Changes
st-v058-byoa-10: authorization and row scoping
core/adapters.queryset_scopeholds it in aContextVar, and everyDynamicModelViewhandler runs inside it.change), inline add-row (addorchange), the update form, delete-file, upload, and single actions (action_<name>, after loading the row under the scope).core/storage_paths.resolve_storage_path, which refuses absolute paths,..and symlink escapes.add/change/deletepermissions are enforced. Primary and foreign keys are never rewritten on update.viewon the target model as well.st-v058-byoa-53: query oracles
core/sensitive.pyandAdminOptions.sensitive_fields(overrides either way). A field is sensitive if it carries the marker or its name matches(^|_)(password|secret|token|hash)(_|$).User.password_hashis marked.qsearch.list_filter.sort_byis limited to displayed, non-sensitive columns; anything else falls back to the default sort with a 200.get_queryset.docs/changelog.md), with an upgrade note for columns such assecret_nameortoken_countthat now count as sensitive.Verification
uv run poe lint: passed.uv run pytest tests -o addopts="" -q -n 4 --ignore=tests/e2e: 996 passed.uv run pytest tests/e2e -o addopts="" -q -n 4: 136 passed.tests/unit/test_dynamic_authz_gaps.pyandtests/unit/test_query_oracles.pywere run against the unfixed code: 22 of 27 and 18 of 36 fail. Every vulnerability test is among the failures; the rest are positive controls.Manual test scenarios
view_<model>, POST an inline cell save: expect 403 and no change.ModelAdmin.get_querysetthat scopes by tenant, open, inline-edit and run an action on another tenant's row: expect 404, and the action does not run.DELETE /admin/<model>/<id>/file/<text field>: expect 404, and the field and any file it names are untouched./admin/user?sort_by=password_hash,?sort_by=nope,?search=<part of a hash>and?filter_password_hash=<hash>: expect the default order and no leaked matches, all with status 200.GET /admin/<model>/choices/<fk>?password_hash=x: the parameter is ignored. With a target admin that hides inactive rows, inactive rows are not offered. Withoutview_<target>, expect 403.🤖 Generated with Claude Code
Files (all under
/Users/yevheniidehtiar/.projects/hyper-admin/.claude/worktrees/wf_0411676f-73e-2):src/hyperadmin/core/storage_paths.py,src/hyperadmin/core/sensitive.py,src/hyperadmin/adapters/_search.py,tests/unit/test_dynamic_authz_gaps.py,tests/unit/test_query_oracles.pysrc/hyperadmin/views/dynamic.py,src/hyperadmin/views/forms.py,src/hyperadmin/core/adapters.py,src/hyperadmin/core/introspection.py,src/hyperadmin/core/options.py,src/hyperadmin/adapters/sqlmodel.py,src/hyperadmin/adapters/sqlalchemy.py,src/hyperadmin/auth/models.py,src/hyperadmin/routing.py,CHANGELOG.md,docs/changelog.md