Restrict rendered template artifacts

This commit is contained in:
2026-08-02 13:58:45 +02:00
parent b65b905b6e
commit 3551c48e14
6 changed files with 91 additions and 18 deletions
@@ -31,6 +31,7 @@ from govoplan_templates.backend.db.models import (
TemplateRevision,
)
from govoplan_templates.backend.service import (
ADMIN_SCOPE,
RENDER_SCOPE,
compatibility,
get_template,
@@ -199,6 +200,14 @@ def get_render_for_principal(
if row is None:
raise TemplateRenderError("Template render not found.")
get_template(session, principal, row.template_id)
if (
row.created_by_account_id != principal.account_id
and not principal.has(ADMIN_SCOPE)
):
# Render payloads may contain recipient-specific or otherwise
# confidential data. Do not reveal whether another actor's render
# exists to ordinary template readers.
raise TemplateRenderError("Template render not found.")
return row
@@ -212,6 +221,10 @@ def list_renders(
statement = select(TemplateRender).where(
TemplateRender.tenant_id == principal.tenant_id
)
if not principal.has(ADMIN_SCOPE):
statement = statement.where(
TemplateRender.created_by_account_id == principal.account_id
)
if template_id:
get_template(session, principal, template_id)
statement = statement.where(TemplateRender.template_id == template_id)