-
Notifications
You must be signed in to change notification settings - Fork 12
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
Changes the format of the signature to allow for later extensions. #18
base: master
Are you sure you want to change the base?
Conversation
- Should be backwards compatible - Uped version to 0.5.0 - Moves from comment to a meta tag inside head - Allows multiple signatures - Allows for a non-minimized signature for firefox users - Adds an allowedMethods field to signatures to limit when the signature can be used. - Adds a version field to signatures to allow updating minimizer in the the future - uses npm-install-version to allow multiple versions of the minimizer to co-exist in the same codebase to allow updates - Updated README
const head = content.split(/<\/head\s*>/i)[0]; | ||
|
||
// Parse signature metadata | ||
const signatureRegex = RegExp('<meta\\s+name="signature"\\s+content="([^"]*)"\\s*>', 'gi'); |
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.
Hmm, so why is that RegEx safe to use? One could also just place this meta string anywhere (also multiple times), possibly even user-generated content or so… (though unlikely for the types of websites we talk about…)
Especially if it then replaces the strings matched by this here for verification… 🤔
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.
I first split on and take only the first part. This ensures I just get the head. I then regex for what I need. Any user content will not be in the head.
I could pass it to DOM parser, but I though this was easier to handle and still safe
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.
Users can affect the head, especially with the prevalence of "og:" tags. Additionally, this parsing is quite strict so it'll break if someone puts the content before the name of any other variation.
src/background.js
Outdated
// Chain promises returning when the first one is true | ||
if (promise) { | ||
last = last.then(verified => { | ||
if (verified) |
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.
Not that sure what you do here, but possible Promise.race
works here, too?
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.
promise.race only returns one value, the first. Promise.all only returns when all the values are completed. This code goes through the signatures one at a time, from first to last and returns true when one of them returns true. Since verification is CPU and not IO, I don't know how much parallelism we actually get.
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.
Updated the code to hopefully be cleaner
Code is cleaner and now returns on first valid signature
Thanks a lot for this! It's very much needed, and I can't wait to review and merge it. However, I have a few comments and a few things I need to think about before reviewing. Comments:
Would become:
Any thoughts on the above? Looking to hearing from you. P.S: obviously this drops support for the current mechanism, but that's absolutely fine. Usage is not yet that widespread, so it's better to just force users to update, than having the legacy code, that may reduce security, remain there. |
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.
See my comment
reject(error); | ||
}))).then(values => { | ||
if (values.every(x => x == false)) | ||
resolve(false) |
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.
Okay, this resolves promises with false
. So it is only supported for promises that return boolean values…
Hey, just chasing this one, as I'm really excited to have it already. :) |
Hey @steamraven, how are you? |
signature can be used.
the future
co-exist in the same codebase to allow updates
Solves #15 and #6. Lays the foundation for solving #1, #2, #13, and #16
Discussion and comments are welcome