Require view permission before returning written rows

This commit is contained in:
Simon Willison 2026-09-08 21:16:35 -07:00
commit a365903d56
2 changed files with 17 additions and 1 deletions

View file

@ -838,7 +838,14 @@ class RowUpdateView(BaseView):
result = {"ok": True}
returned_row = None
if data.get("return"):
# Only read back and disclose the stored row if the actor is also
# allowed to view this table - update-row alone must not be usable
# to read data the actor cannot otherwise see.
if data.get("return") and await self.ds.allowed(
action="view-table",
resource=TableResource(database=resolved.db.name, table=resolved.table),
actor=request.actor,
):
results = await resolved.db.execute(
resolved.sql, resolved.params, truncate=True
)

View file

@ -1157,6 +1157,15 @@ class TableInsertView(BaseView):
# TODO: narrow to expected write errors so Datasette bugs surface as 500s
return Response.error([str(e)])
result = {"ok": True}
# Only read back and disclose stored rows if the actor is also
# allowed to view this table - insert-row/update-row alone must
# not be usable to read data the actor cannot otherwise see.
if should_return and not await self.ds.allowed(
action="view-table",
resource=TableResource(database=database_name, table=table_name),
actor=request.actor,
):
should_return = False
if should_return:
if upsert:
# Fetch based on initial input IDs