fa4b2d412f
The `SUPPORTED_MEDIA_DOMAINS` regex whitelist, used to check if media link comes from trusted hosts is invalid. It does not expose a security risk or I couldn't find an example for such as of now, but if someone would add a subdomain host to it using the same pattern, it would.
A counter example below:
```js
const SUPPORTED_MEDIA_DOMAINS = /^([^.]+\.)*(ytimg.com|cdninstagram.com|redd.it|imgur.com|fbcdn.net|pinimg.com)$/i;
console.log('Testing redd.it: ' + SUPPORTED_MEDIA_DOMAINS.test('redd.it'));
console.log('Testing reddjit: ' + SUPPORTED_MEDIA_DOMAINS.test('reddjit'));
```
Output:
```
$ node example.js
Testing redd.it: true
Testing reddjit: true
```
---
To be more clear, if someone would extend the regex in the future with e.g. `media.redd.it`, an attacker would be able to create a `mediaXredd.it` domain and bypass the whitelist.
---
A visualisation of the incorrect regex can be found on https://regexper.com/#%5E%28%5B%5E.%5D%2B%5C.%29*%28ytimg.com%7Ccdninstagram.com%7Credd.it%7Cimgur.com%7Cfbcdn.net%7Cpinimg.com%29%24
The issue has been found with LGTM:
|
||
---|---|---|
.. | ||
metadata | ||
migrations | ||
types | ||
views | ||
.eslintrc | ||
attachment_downloads.js | ||
auto_orient_image.js | ||
backup.js | ||
crypto.js | ||
data.d.ts | ||
data.js | ||
database.js | ||
debug.js | ||
debuglogs.js | ||
deferred_to_promise.d.ts | ||
deferred_to_promise.js | ||
emojis.js | ||
i18n.js | ||
idle_detector.js | ||
indexeddb.js | ||
link_previews.d.ts | ||
link_previews.js | ||
logs.js | ||
messages_data_migrator.js | ||
migrate_to_sql.js | ||
privacy.js | ||
refresh_sender_certificate.js | ||
settings.js | ||
signal.js | ||
sleep.js | ||
stickers.d.ts | ||
stickers.js | ||
string_to_array_buffer.js | ||
web_api.js |