Skip to content

fix(iiif): validate expected shape of identifiers#2234

Open
max-moser wants to merge 2 commits intoinveniosoftware:masterfrom
max-moser:mm/iiif-id-shape
Open

fix(iiif): validate expected shape of identifiers#2234
max-moser wants to merge 2 commits intoinveniosoftware:masterfrom
max-moser:mm/iiif-id-shape

Conversation

@max-moser
Copy link
Copy Markdown
Contributor

Some IIIF API endpoints expect passed identifiers to have a specific shape (either two or three separator colons).
Currently, this is not validated beyond a simple id.split(":") which causes a 500 internal server error if the identifier doesn't match the expected shape.

This PR introduces a new exception type that indicates the case that an identifier did not match the expected shape.


We assume the uuid is build as ``<record|draft>:<pid_value>``.
"""
type_, id_ = uuid.split(":", 1)
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.

remove the maxsplit argument to have a more accurate reading of the number of separator colons in the full string

this could be an issue if pid_value was allowed to have a colon inside it, which is not the case for RECIDs out of the box
if they do, the _iiif_image_uuid() check might be even worse off


We assume the uuid is build as ``<record|draft>:<pid_value>:<key>``.
"""
type_, id_, key = uuid.split(":", 2)
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.

perhaps the maxsplit argument should be added back here, because the key might be allowed to have colons in it?
then (with maxsplit), the key could have as few/many colons as desired; but pid_value still cannot be allowed to have colons (because otherwise we can't reliably determine pid_value vs. key)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we do any kind of validation on the file key. It might be a good idea to add maxsplit back on this one.

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.

done!

* identifiers mismatching the expectations about the number of separator
  colons
* validate if the requested identifier matches the expected shape, and
  raise a new dedicated error type if that is not the case
@github-actions
Copy link
Copy Markdown
Contributor

This PR was automatically marked as stale.

@github-actions github-actions bot added the stale label Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants