qsniyg / maxurl

Finds larger/original versions of images and videos
https://qsniyg.github.io/maxurl/
Apache License 2.0
1.14k stars 73 forks source link

Tumblr image URL not working because it tries to parse JS as JSON #1056

Open Crul opened 2 years ago

Crul commented 2 years ago

Affects: Firefox Addon v0.19.5

Steps to reproduce

  1. Navigate to https://64.media.tumblr.com/9e9d07664bd68d9fc36c5aeaf3d9b83d/cd60a7e1e46554d3-8e/s500x750/12c05728ddf181dc39caa05a51a02fbeeb9d38d7.jpg
  2. Execute the addon
  3. This error appears on the console:
    SyntaxError: JSON.parse: unexpected character at line 1 column 20 of the JSON data
    get_initialstate_from_text
    onload
    request_final
    general_extension_message_handler
    do_mouseover

Pointing to the this code:

var json = match[1].replace(/(\"\s*:)\s*\/.*?\/\s*([,}])/g, "$1null$2");
try {
    var parsed = JSON_parse(json);
    return parsed;
} catch (e) {
    console_error(e);
}

The problem is that json does not contain a valid JSON string (full value below) because it includes undefined values (not supported) and a property with a new RegExp(...) object. If you change var parsed = JSON_parse(json); with var parsed = eval(json);, it works, but I'm not sure that's a safe way to do it.

Thanks!

{"cookieBootstrap":undefined,"routeSet":"media","routeUsesPalette":false,"routeHidesLowerRightContent":false,"routeName":"image-url-page","isInitialRequestPeepr":false,"isInitialRequestSSRModal":false,"viewport-monitor":{"height":800,"width":1280},"chunkNames":["image-url-page"],"ImageUrlPage":{"requestedImage":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs999999999x999999999\u002Fd241330421e102771fa470084f2e355f1c738be2.jpg","altText":"","photo":{"imageResponse":[{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":1080,"height":1080,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs1280x1920\u002Fc0fe31f74672d1cf9b74e0243327d152ecf1d6e1.jpg","colors":{"c0":"020939","c1":"000208"},"hasOriginalDimensions":true},{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":640,"height":640,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs640x960\u002Fb3c3fa5aea8fb0c20d0f173cb1c8fc0e55c8f71f.jpg","colors":{"c0":"020939","c1":"000208"}},{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":540,"height":540,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs540x810\u002Fd648c8c8ab7d9cffe5e70477796c88c85b3bd606.jpg","colors":{"c0":"020939","c1":"000208"}},{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":500,"height":500,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs500x750\u002F12c05728ddf181dc39caa05a51a02fbeeb9d38d7.jpg","colors":{"c0":"020939","c1":"000208"}},{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":400,"height":400,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs400x600\u002F214d71e856bf92010877281fe178724b58bef325.jpg","colors":{"c0":"020939","c1":"000208"}},{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":250,"height":250,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs250x400\u002Fd7be2705a255c8868dd83717a56787bb8fd20e66.jpg","colors":{"c0":"020939","c1":"000208"}},{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":250,"height":250,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs250x250_c1\u002F98e50bdd59bb613ec9dfd61cf5e2f5a3164cac9b.jpg","colors":{"c0":"020939","c1":"000208"},"cropped":true},{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":100,"height":100,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs100x200\u002F30b6652e4327f61b25e01716ff8fcd2094d787bd.jpg","colors":{"c0":"020939","c1":"000208"}},{"mediaKey":"9e9d07664bd68d9fc36c5aeaf3d9b83d:cd60a7e1e46554d3-8e","type":"image\u002Fjpeg","width":75,"height":75,"url":"https:\u002F\u002F64.media.tumblr.com\u002F9e9d07664bd68d9fc36c5aeaf3d9b83d\u002Fcd60a7e1e46554d3-8e\u002Fs75x75_c1\u002Fb3b8408792faf2f2a855f1c4b95b867e80faa70a.jpg","colors":{"c0":"020939","c1":"000208"},"cropped":true}]},"post":{"postUrl":"https:\u002F\u002Fwarakami-vaporwave.tumblr.com\u002Fpost\u002F622569349976309760\u002F90s-wave-midnight-follow-me-on-instagram","postId":"622569349976309760","tag":"neon"},"blog":{"name":"warakami-vaporwave","title":"Warakami Vaporwave","avatar":[{"width":512,"height":512,"url":"https:\u002F\u002F64.media.tumblr.com\u002Fb4959947fedb4b67e4bcb9bfdac7a244\u002Fa25af9a8b60ee6a2-e7\u002Fs512x512u_c1\u002F3722169380073300249c928d64a243f3c1feff24.jpg"},{"width":128,"height":128,"url":"https:\u002F\u002F64.media.tumblr.com\u002Fb4959947fedb4b67e4bcb9bfdac7a244\u002Fa25af9a8b60ee6a2-e7\u002Fs128x128u_c1\u002F5b0e0d612b7628959d5fcfc915bcd5f3a0f0055b.jpg"},{"width":96,"height":96,"url":"https:\u002F\u002F64.media.tumblr.com\u002Fb4959947fedb4b67e4bcb9bfdac7a244\u002Fa25af9a8b60ee6a2-e7\u002Fs96x96u_c1\u002F79f999abbc71965321e5e3bdc1fcc08314d14c82.jpg"},{"width":64,"height":64,"url":"https:\u002F\u002F64.media.tumblr.com\u002Fb4959947fedb4b67e4bcb9bfdac7a244\u002Fa25af9a8b60ee6a2-e7\u002Fs64x64u_c1\u002F82f540f7f84248e20f24d94906025edb884de148.jpg"}],"description":"Vaporwave Anime Pop Art .JP","url":"https:\u002F\u002Fwarakami-vaporwave.tumblr.com\u002F"}},"queries":{"mutations":[],"queries":[]},"apiUrl":"https:\u002F\u002Fapi.tumblr.com","apiFetchStore":{"API_TOKEN":"aIcXSOoTtqrzR8L8YEIOmBeW94c3FmbSNSWAUbxsny9KKx5VFh","extraHeaders":"{\"X-IS-BLOG-NETWORK\":\"1\"}"},"cspNonce":"M2M5MGMzNTg1ZGQ5MWJkOTdjYWE1YjdkYjNmYThlYmE=","languageData":{"code":"en_US","data":{}},"configRef":{"flags":""},"reportingInfo":{"host":"[www.tumblr.com](chrome://devtools/content/webconsole/www.tumblr.com)","token":"1659539901122|1ae0dc3393e958aff12f9a50ae10405e"},"analyticsInfo":{"kraken":{"basePage":"ImageUrlPage","routeSet":"media","krakenBaseUrl":"https:\u002F\u002Fls.srvcs.tumblr.com","sessionId":"cbccc73e-93dc-455b-b518-8bf60f4d3610","clientDetails":{"platform":"Redpop","os_name":"Windows","os_version":"10","language":"en_US","build_version":"3ea89c73c328f50df0a43336975c71868503a64b","form_factor":"Desktop","model":"","connection":"","carrier":"","browser_name":"Firefox","browser_version":"103.0"},"configRef":{"flags":""}}},"tumblelogAuthToken":undefined,"adPlacementConfiguration":{},"privacy":{},"endlessScrollingDisabled":undefined,"bestStuffFirstDisabled":undefined,"colorizedTags":undefined,"autoTruncatingPosts":undefined,"timestamps":undefined,"contentWarningSetting":undefined,"labsSettings":undefined,"wwwBaseUrl":"https:\u002F\u002Fwww.tumblr.com","isLoggedIn":{"isPartiallyRegistered":false,"isLoggedIn":false,"isAdmin":undefined},"recaptchaV3PublicKey":{"value":"6Ld2ca0UAAAAAKzttOGcjomH-5rBIJesbQrCZtfB"},"obfuscatedFeatures":"e30=","supportedBrowserRegexp":new RegExp("((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(12|(1[3-9]|[2-9]\\d|\\d{3,})|14|(1[5-9]|[2-9]\\d|\\d{3,})|15|(1[6-9]|[2-9]\\d|\\d{3,}))[_.]\\d+(?:[_.]\\d+)?)|(Opera Mini(?:\\\u002Fatt)?\\\u002F?(\\d+)?(?:\\.\\d+)?(?:\\.\\d+)?)|(Opera\\\u002F.+Opera Mobi.+Version\\\u002F(64|(6[5-9]|[7-9]\\d|\\d{3,}))\\.\\d+)|(Opera\\\u002F(64|(6[5-9]|[7-9]\\d|\\d{3,}))\\.\\d+.+Opera Mobi)|(Opera Mobi.+Opera(?:\\\u002F|\\s+)(64|(6[5-9]|[7-9]\\d|\\d{3,}))\\.\\d+)|((?:Chrome).*OPR\\\u002F(85|(8[6-9]|9\\d|\\d{3,}))\\.\\d+\\.\\d+)|(SamsungBrowser\\\u002F(16|(1[7-9]|[2-9]\\d|\\d{3,}))\\.\\d+)|(Edge\\\u002F(102|(10[3-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,}))(?:\\.\\d+)?)|((Chromium|Chrome)\\\u002F(101|(10[2-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,}))\\.\\d+(?:\\.\\d+)?)|(Version\\\u002F(15|(1[6-9]|[2-9]\\d|\\d{3,}))\\.\\d+(?:\\.\\d+)? Safari\\\u002F)|(Firefox\\\u002F(91|(9[2-9]|\\d{3,})|101|(10[2-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,}))\\.\\d+\\.\\d+)|(Firefox\\\u002F(91|(9[2-9]|\\d{3,})|101|(10[2-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,}))\\.\\d+(pre|[ab]\\d+[a-z]*)?)", ""),"cssMapUrl":"https:\u002F\u002Fassets.tumblr.com\u002Fpop\u002Fcssmap-d31245ab.json"}
qsniyg commented 2 years ago

Are you using the latest git version? I'm unable to replicate the issue on my end with the latest git version. Though you're right that it doesn't handle undefined in that section of the code, that's for posts (I'm not sure if it needs to handle it or not?). For images (like the one you shared), it handles undefined:

var json = match[1].replace(/(\"\s*:)\s*(?:\/.*?\/|undefined|new RegExp\(.*?\))\s*([,}])/g, "$1null$2");

Crul commented 2 years ago

@qsniyg Indeed, I cannot replicate it in the same way, but it still doesn't work.

Now it says No media info (on check_image_get) because obj[0] is this object with no media_info property:

{ waiting: true, url: "https://64.media.tumblr.com/9e9d07664bd68d9fc36c5aeaf3d9b83d…4d3-8e/s500x750/12c05728ddf181dc39caa05a51a02fbeeb9d38d7.jpg" }

I don't know if that's correct; because I can access a larger verion if I change s500x750 with `s999999999x999999999:

https://64.media.tumblr.com/9e9d07664bd68d9fc36c5aeaf3d9b83d/cd60a7e1e46554d3-8e/s999999999x999999999/d241330421e102771fa470084f2e355f1c738be2.jpg

... but I have no idea what I'm talking about, so feel free to close this issue if you think it's working as expected.

Thanks.

qsniyg commented 2 years ago

Can you send your settings? (through the Export button at the top)

Crul commented 2 years ago

Sure, here you have it (bottom). I should also point out that I have some (40, full list below) addons installed. I tried to make sure they are not interfering with this issue. Info no my previous comment was gathered after disabling uMatix, uBlock Origin, TamperMonkey and Request Control. But I may have missed something... sorry if that's the case.

Again, feel free to clsoe the issue if you cannot replicate it, because in that case I think it's most probably my fault. Thanks.