Active Storage Permanent Urls Expired After Upgrading to Rails 7

After upgrading to Rails 7, it seems that the active storage permanent urls which we got from url_for(file) that were previously working have now expired. Why did that happen? Is it possible to get them working again? This was a bad design on our part, but we allowed users to create their own content which included hardcoding those permanent urls in to that content.

So our old links that look like this:

https:://example.com/rails/active_storage/blobs/redirect/eyJfcmFpbHGyOnvGaTVzc2FnZSI6IkJBaHBBajhSIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iG2hkIn19–58d2b87749167071f0bb2c1e6199267f4c78b0c0/example.pdf

no longer works.

:frowning:

We’ve stumbled upon this error a few times. It’s one of the more annoying problems in active storage. The signed_ids generated are dependent on multiple things, like the master key, the digest algorithm, pourpose, etc.

I think in your case, you got caught by one of the changes in Rails 7: The key generator changed digest class from SHA-1 to SHA256. Just click the link below to see how to perform this upgrade by rotating the keys.

Don’t try to simply revert the generator to SHA-1 as that will break the urls for things you generated after upgrading.

Also, don’t feel bad about hardcoding the urls. ActionText does that too, so you can say it has official approval :wink: