-
Notifications
You must be signed in to change notification settings - Fork 2
feat: allow downloads only from trusted origins and with approved file types #40
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
base: master
Are you sure you want to change the base?
Conversation
7daf573
to
07c0027
Compare
@633kh4ck kindly review 🙏 |
} | ||
|
||
const matchingRule = downloadWhitelist.find(rule => { | ||
const ruleOriginRegex = stringWhitelistToRegex(rule.origin); |
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.
Do we really need it to be Regex?
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 just took over this issue. What's the requirements here?
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.
const matchingRule = downloadWhitelist.find(rule => { | ||
const ruleOriginRegex = stringWhitelistToRegex(rule.origin); | ||
|
||
return ruleOriginRegex.test(origin) && rule.allowedFileExtensions.includes(fileExtension); |
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.
Subject to 'type confusion'-like issue 12. Type-check allowedFileExtensions
:
const fileExtension = 'js'
const downloadWhitelist = [{
origin: 'https://example.com',
allowedFileExtensions: 'json'
}]
const result = downloadWhitelist.find(rule => {
return rule.allowedFileExtensions.includes(fileExtension)
})
!!result // oops
This adds origin-based validation to download requests, ensuring only requests from explicitly allowed origins and approved file types are processed. Enhances security by preventing unauthorised download triggers.
Closes #42