Skip to content

Conversation

@davidwessman
Copy link
Contributor

@davidwessman davidwessman commented Oct 4, 2024

  • Adds expires_in and secret_key to download_endpoint plugin
  • This allows calling attachment.download_url(expires_in: 5 * 60)
    to generate a URL including signature and expires_at as query parameters. The timestamp is included in the signature and will only work before that timestamp.
  • The URL is signed and verified with HMAC with SHA256 digest.

@adam12
Copy link
Contributor

adam12 commented Oct 4, 2024

I suspect the use of AS::Verifier is going to be an issue. We might need to go with OpenSSL::HMAC directly.

@davidwessman
Copy link
Contributor Author

I suspect the use of AS::Verifier is going to be an issue. We might need to go with OpenSSL::HMAC directly.

I'll try it out 🙂

@janko
Copy link
Member

janko commented Oct 4, 2024

Yes, Shrine doesn't depend on Active Support, so I want to avoid it if possible, even as an optional dependency. The derivation_endpoint plugin has URL signing implemented using OpenSSL::HMAC, so you can take a look there.

@davidwessman
Copy link
Contributor Author

Now I rewrote it to use OpenSSL-directly 🙂
Not sure if some of this functionality should be extracted to the UrlSigner class.

@davidwessman davidwessman requested a review from janko October 5, 2024 17:21
Copy link
Contributor

@adam12 adam12 left a comment

Choose a reason for hiding this comment

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

Nicely done adapting it for OpenSSL::HMAC. Few comments but overall looks good IMHO. Will leave final sign-off for Janko ofc.

@davidwessman davidwessman requested a review from adam12 October 15, 2024 11:26
@davidwessman
Copy link
Contributor Author

@janko could you allow the tests to run? They crash on my side because of libmagic

@davidwessman
Copy link
Contributor Author

@janko Sorry for a second (and last) ping, do you think there would be bandwidth for handling this PR within November?
Totally understandable if you do not know, trying to plan our alternatives with some deadlines coming up.
Thank you for great gems! 🙂

@adam12
Copy link
Contributor

adam12 commented Jun 24, 2025

Please rebase if willing. Then we can trigger tests to run and maybe get this over the finish line.

- Adds `expires_in` and `verifier_secret` to `download_endpoint` plugin
- This allows calling `attachment.download_url(expires_in: 5 * 60)`
  to generate a URL that expires in 5 minutes.
- The URL is signed and verified with ActiveSupport::MessageVerifier.
@davidwessman
Copy link
Contributor Author

Please rebase if willing. Then we can trigger tests to run and maybe get this over the finish line.

Now I have rebased it, please trigger the tests 🙂

@adam12
Copy link
Contributor

adam12 commented Jun 25, 2025

This looks good! Nicely done.

I'll merge later today.

@adam12 adam12 merged commit e572673 into shrinerb:master Jun 25, 2025
7 of 9 checks passed
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.

3 participants