Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement]: remote_api_tokens should use URL Patterns instead of regular expressions #7518

Open
1 task done
keturn opened this issue Jan 5, 2025 · 0 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@keturn
Copy link
Contributor

keturn commented Jan 5, 2025

Is there an existing issue for this?

  • I have searched the existing issues

What should this feature add?

API tokens should be registered as URL patterns instead of by regular expression.

At the moment, the obvious way (and explicitly endorsed by example configuration) to set up a token for the host private.example is:

remote_api_tokens:
  - url_regex: 'private.example'
    token: 'secret'

however, that will leak the secret when given a URL like https://malicious.example/private.example/theft.safetensors or https://private.example.malicious.example/theft.safetensors.

It's possible to write a secure regular expression, but highly unlikely. It requires something like ^https://private\.example/, or if you want to allow subdomains, maybe ^https://([^\[@/:]+\.)?private\.example/

In contrast, URL Patterns do not allow a hostname to accidentally match a path component, or a subdomain to be mistaken for a full host component.

Alternatives

forget patterns; strict string equality matching on hostname only.

Additional Content

A Python interface to URL Patterns is available at https://github.com/urlpattern/python-urlpattern

@keturn keturn added the enhancement New feature or request label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant