• Andrew Clark's avatar
    Use file name whitelist to prevent RCE (#4866) · 24b101d2
    Andrew Clark authored
    * Use file name whitelist to prevent RCE
    
    Use a whitelist to validate user-provided file names. This doesn't cover
    the entire range of valid filenames but should cover almost all of them
    in practice. Allows letters, numbers, periods, dashes, and underscores.
    Opting to use a whitelist instead of a blacklist because getting this
    wrong leaves us vulnerable to a RCE attack.
    
    * Allow alphabet characters from all languages
    
    Updated the whitelist to /^[\p{L}0-9/.\-_]+$/u, which matches
    alphanumeric characters, periods, dashes, and underscores. Unicode
    property support is stage 4 so I've inlined the transpiled version.
    
    * Only use file name whitelist on Windows
    
    * Log error message if file name does not pass whitelist
    24b101d2