Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mzndako
Copy link

@mzndako mzndako commented Apr 4, 2025

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


@mzndako mzndako added the enhancement New feature or request label Apr 4, 2025
@mzndako mzndako requested a review from 633kh4ck April 4, 2025 10:54
@mzndako mzndako self-assigned this Apr 4, 2025
@mzndako mzndako requested a review from timlanahan April 9, 2025 00:46
@mzndako mzndako force-pushed the mz/feat/download-origin-whitelist branch from 7daf573 to 07c0027 Compare April 9, 2025 01:30
@mzndako mzndako changed the title feat: restrict download requests to allowed origins feat: allow downloads only from trusted origins and with approved file types Apr 9, 2025
@mzndako
Copy link
Author

mzndako commented Apr 9, 2025

@633kh4ck kindly review 🙏

}

const matchingRule = downloadWhitelist.find(rule => {
const ruleOriginRegex = stringWhitelistToRegex(rule.origin);

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?

Copy link

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?

Copy link

@633kh4ck 633kh4ck May 22, 2025

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);

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

Footnotes

  1. https://cwe.mitre.org/data/definitions/843.html

  2. https://snyk.io/es/blog/remediate-javascript-type-confusion-bypassed-input-validation/

@kevva kevva assigned kevva and unassigned mzndako Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only allow downloads from trusted origins with approved file types
3 participants