-
Notifications
You must be signed in to change notification settings - Fork 150
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 foruuid
.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.