Skip to content

dao_get_template_email_file_by_id: look up the file by service ID too - #4948

Draft
joybytes wants to merge 1 commit into
mainfrom
filter-template-email-file-by-service-id
Draft

dao_get_template_email_file_by_id: look up the file by service ID too#4948
joybytes wants to merge 1 commit into
mainfrom
filter-template-email-file-by-service-id

Conversation

@joybytes

Copy link
Copy Markdown
Contributor

Summary

Make dao_get_template_email_file_by_id take the service ID, and pass the service and template IDs from the get_template_email_file_by_id endpoint. The DAO joins on templates to check the file belongs to that service, and optionally checks it belongs to that template.

This came from the scan report which said: The endpoint looked files up by file ID alone, so the service and template in the URL were ignored. The admin app already does the authorisation checks, so this is not exploitable and was triaged as low, but we want the DAO to filter by service ID like it does elsewhere.
Checking the template ID as well is worth having because of restricted template folders: within one service a user can be allowed to see one template but not another, so the file should have to belong to the template in the URL, not just the service.

The internal API trusted the file ID on its own, so a mismatched service
or template in the URL still returned the file. The admin app blocks this,
so it was not exploitable, but the DAO should enforce it as well.

Service ID is now required and the caller can also pass the template ID,
which matters where a user can see one template in a service but not
another because of restricted folders. A file that does not match the
route now raises NoResultFound, which the API turns into a 404.
@autocommit
def dao_get_template_email_file_by_id(template_email_file_id):
return TemplateEmailFile.query.filter(TemplateEmailFile.id == template_email_file_id).one()
def dao_get_template_email_file_by_id(service_id, template_email_file_id, template_id=None):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if this function should be through replica

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant