element-hq / matrix-content-scanner-python

A web service for scanning media hosted by a Matrix media repository
Apache License 2.0
13 stars 9 forks source link

Add validation utils for encrypted file metadata #25

Closed babolivier closed 2 years ago

babolivier commented 2 years ago

When scanning an encrypted file, clients are expected to send the content scanner some metadata it can use to decrypt it. This is typically the file property of the m.room.message event content. See https://github.com/matrix-org/matrix-content-scanner-python/blob/main/docs/api.md#post-_matrixmedia_proxyunstabledownload_encrypted to see how it fits into the API, and an example.

This adds a validate_encrypted_file_metadata util that performs a few validation checks on the client-provided data to ensure it's in the right format before passing it on to the scanner. This will then be used by the http handler code (coming in a future PR, see https://github.com/matrix-org/matrix-content-scanner-python-wip/blob/main/matrix_content_scanner/servlets/__init__.py#L166-L241 to see what it will looks like).

Closes #7