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
let signed_id of ActiveStorge::Blob be striped from as an id #211
Conversation
Signed-off-by: Reza J. Bavaghoush <rzjfr@yahoo.com>
@@ -91,6 +91,7 @@ def strip_ids_from_path(path) | |||
path | |||
.gsub(%r{/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(/|$)}, '/:uuid\\1') | |||
.gsub(%r{/\d+(/|$)}, '/:id\\1') | |||
.gsub(%r{/[0-9a-zA-Z=]+--[0-9a-f]+(/|$)}, '/:signed_id\\1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR!
I'm a little worried that this Regex is a bit broad. It'll match almost any part of a path that has --
in the middle. This is admittedly rare, but i'm wondering if we can narrow it down a bit more, probably by specifying the length of these parts, like we do for uuid
.
I have no experience with ActiveStorage unfortunately, but reading through the code, i believe this is where the Signed ID gets generated: https://github.com/rails/rails/blob/afc79e3cb0906d06b035ef30411c44ddc2132409/activesupport/lib/active_support/message_verifier.rb#L186-L203
And if i'm reading that correctly, i'd expect the first half of the signed ID (before the --
) can be any length, but the digest should always be the same length (40 chars), right?
I notice your test case has a shorter digest, i'm not sure whether you're using an actual Signed ID generated by Rails, which would invalidate my suggestion, or if it was manual random typing...
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing the PR,
I completely agree with that point, we should make the regex stricter.
Regarding the signature id, though my example was bogus, unfortunately lengths is not always 40, thought the default is SHA1, but it could be changed:
https://github.com/rails/rails/blob/afc79e3cb0906d06b035ef30411c44ddc2132409/activesupport/lib/active_support/message_verifier.rb#L109
Most likely to something like SHA-256 which is 64 chars but extremely rare (rarer than "having -- in path" rare) for anyone to change it to anything less than MD5 which is 32.
Also the first part (before --) also should be a valid base64 encoded string so a not a complex overkill regex might look like this:
(?=(.{4})*--)[A-Za-z0-9]+={0,2}--[0-9a-f]{32,}
I can also add negative test case to the specs.
Hi @rzjfr, sorry we went quiet on this PR. After some issues caused by us trying to get too clever with how we process URLs in the collector middleware, we've decided to keep it simple for now. For the time being, we're encouraging anyone who wants to customise how paths are generated to extend I appreciate that it's a little more code on your side, but we'd like to keep our path generation logic deliberately simple, and let people add their framework-specific customisations to it. At some point we may revisit that decision, but the earliest that will happen is version 5 we've been treating changes to automatically generated labels as breaking (since they might break dashboards/alerts that people have set up). |
Strip signed_id of Rails ActiveStorge::Blob by default like normal IDs and UUIDs