Skip to content

Js sandbox causing errors #486

Description

@Blatzar

Describe the bug

9e254cc seems to have caused issues with eval_in_node()

Without modifications it gives NameError: name 'path' is not defined

Editing https://github.com/vn-ki/anime-downloader/blob/master/anime_downloader/util.py#L402 to os.path will result in error below

To reproduce

anime -ll DEBUG dl "hunter x hunter" --provider animekisa -c 2
LOG
bl@arch ~> anime -ll DEBUG dl "hunter x hunter" --provider animekisa -c 2
2020-08-22 14:01:28 arch anime_downloader.util[84260] INFO anime-downloader 4.6.3
2020-08-22 14:01:28 arch anime_downloader.util[84260] DEBUG Platform: Linux-5.7.7-arch1-1-x86_64-with-glibc2.2.5
2020-08-22 14:01:28 arch anime_downloader.util[84260] DEBUG Python 3.8.3
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG GET https://animekisa.tv/search
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {'params': {'q': 'hunter x hunter'}}
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5'}                                        
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.session[84260] DEBUG cached request
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG https://animekisa.tv/search?q=hunter+x+hunter                                                                                                                  
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG /tmp/animedlm6tlqktt/tmpzys605nr
+--------+--------------------------------------------------+--------+
|     12 | Hunter x Hunter Movie 2: The Last Mission        |        |
|     11 | Hunter x Hunter Movie 2: The Last Mission Dubbed |        |
|     10 | Hunter x Hunter: Phantom Rouge                   |        |
|      9 | Hunter x Hunter: The Last Mission                |        |
|      8 | Hunter x Hunter: Phantom Rouge Dubbed            |        |
|      7 | Hunter x Hunter Dubbed                           |        |
|      6 | Hunter x Hunter (2011) Dubbed                    |        |
|      5 | Hunter X Hunter OVA 2                            |        |
|      4 | Hunter X Hunter OVA                              |        |
|      3 | Hunter X Hunter OVA 3                            |        |
|      2 | Hunter X Hunter                                  |        |
|      1 | Hunter x Hunter (2011)                           |        |
|--------+--------------------------------------------------+--------|
|   SlNo | Title                                            | Meta   |
+--------+--------------------------------------------------+--------+
2020-08-22 14:01:28 arch anime_downloader.util[84260] INFO Selected Hunter X Hunter
2020-08-22 14:01:28 arch anime_downloader.sites.anime[84260] INFO Extracting episode info from page
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG GET https://www.animekisa.tv/hunter-x-hunter                                                                                                                   
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {}
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5'}                                        
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.session[84260] DEBUG cached request
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG https://animekisa.tv/hunter-x-hunter
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG /tmp/animedlm6tlqktt/tmpainpf2o4
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG GET https://www.animekisa.tv/hunter-x-hunter                                                                                                                   
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {}
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5'}                                        
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.session[84260] DEBUG cached request
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG https://animekisa.tv/hunter-x-hunter
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG /tmp/animedlm6tlqktt/tmpls19pkb8
2020-08-22 14:01:28 arch anime_downloader.sites.anime[84260] DEBUG EPISODE IDS: length: 62, ids: ['https://animekisa.tv/hunter-x-hunter-episode-1', 'https://animekisa.tv/hunter-x-hunter-episode-2', 'https://animekisa.tv/hunter-x-hunter-episode-3', 'https://animekisa.tv/hunter-x-hunter-episode-4', 'https://animekisa.tv/hunter-x-hunter-episode-5', 'https://animekisa.tv/hunter-x-hunter-episode-6', 'https://animekisa.tv/hunter-x-hunter-episode-7', 'https://animekisa.tv/hunter-x-hunter-episode-8', 'https://animekisa.tv/hunter-x-hunter-episode-9', 'https://animekisa.tv/hunter-x-hunter-episode-10', 'https://animekisa.tv/hunter-x-hunter-episode-11', 'https://animekisa.tv/hunter-x-hunter-episode-12', 'https://animekisa.tv/hunter-x-hunter-episode-13', 'https://animekisa.tv/hunter-x-hunter-episode-14', 'https://animekisa.tv/hunter-x-hunter-episode-15', 'https://animekisa.tv/hunter-x-hunter-episode-16', 'https://animekisa.tv/hunter-x-hunter-episode-17', 'https://animekisa.tv/hunter-x-hunter-episode-18', 'https://animekisa.tv/hunter-x-hunter-episode-19', 'https://animekisa.tv/hunter-x-hunter-episode-20', 'https://animekisa.tv/hunter-x-hunter-episode-21', 'https://animekisa.tv/hunter-x-hunter-episode-22', 'https://animekisa.tv/hunter-x-hunter-episode-23', 'https://animekisa.tv/hunter-x-hunter-episode-24', 'https://animekisa.tv/hunter-x-hunter-episode-25', 'https://animekisa.tv/hunter-x-hunter-episode-26', 'https://animekisa.tv/hunter-x-hunter-episode-27', 'https://animekisa.tv/hunter-x-hunter-episode-28', 'https://animekisa.tv/hunter-x-hunter-episode-29', 'https://animekisa.tv/hunter-x-hunter-episode-30', 'https://animekisa.tv/hunter-x-hunter-episode-31', 'https://animekisa.tv/hunter-x-hunter-episode-32', 'https://animekisa.tv/hunter-x-hunter-episode-33', 'https://animekisa.tv/hunter-x-hunter-episode-34', 'https://animekisa.tv/hunter-x-hunter-episode-35', 'https://animekisa.tv/hunter-x-hunter-episode-36', 'https://animekisa.tv/hunter-x-hunter-episode-37', 'https://animekisa.tv/hunter-x-hunter-episode-38', 'https://animekisa.tv/hunter-x-hunter-episode-39', 'https://animekisa.tv/hunter-x-hunter-episode-40', 'https://animekisa.tv/hunter-x-hunter-episode-41', 'https://animekisa.tv/hunter-x-hunter-episode-42', 'https://animekisa.tv/hunter-x-hunter-episode-43', 'https://animekisa.tv/hunter-x-hunter-episode-44', 'https://animekisa.tv/hunter-x-hunter-episode-45', 'https://animekisa.tv/hunter-x-hunter-episode-46', 'https://animekisa.tv/hunter-x-hunter-episode-47', 'https://animekisa.tv/hunter-x-hunter-episode-48', 'https://animekisa.tv/hunter-x-hunter-episode-49', 'https://animekisa.tv/hunter-x-hunter-episode-50', 'https://animekisa.tv/hunter-x-hunter-episode-51', 'https://animekisa.tv/hunter-x-hunter-episode-52', 'https://animekisa.tv/hunter-x-hunter-episode-53', 'https://animekisa.tv/hunter-x-hunter-episode-54', 'https://animekisa.tv/hunter-x-hunter-episode-55', 'https://animekisa.tv/hunter-x-hunter-episode-56', 'https://animekisa.tv/hunter-x-hunter-episode-57', 'https://animekisa.tv/hunter-x-hunter-episode-58', 'https://animekisa.tv/hunter-x-hunter-episode-59', 'https://animekisa.tv/hunter-x-hunter-episode-60', 'https://animekisa.tv/hunter-x-hunter-episode-61', 'https://animekisa.tv/hunter-x-hunter-episode-62']                                                      
2020-08-22 14:01:28 arch anime_downloader.commands.dl[84260] INFO Found anime: Hunter X Hunter
2020-08-22 14:01:28 arch anime_downloader.commands.dl[84260] INFO Downloading to /home/bl
2020-08-22 14:01:28 arch anime_downloader.sites.anime[84260] DEBUG Extracting stream info of id: https://animekisa.tv/hunter-x-hunter-episode-1                                                                                             
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG GET https://animekisa.tv/hunter-x-hunter-episode-1                                                                                                             
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {}
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5'}                                        
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.session[84260] DEBUG cached request
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG https://animekisa.tv/hunter-x-hunter-episode-1                                                                                                                 
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG /tmp/animedlm6tlqktt/tmp8na8u6fg
2020-08-22 14:01:28 arch anime_downloader.sites.animekisa[84260] DEBUG Preferred server gcloud not found. Trying all supported servers                                                                                                      
2020-08-22 14:01:28 arch anime_downloader.sites.anime[84260] DEBUG Sources : [('mp4upload', 'https://www.mp4upload.com/embed-x50ng81bqkhy.html')]                                                                                           
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG GET https://www.mp4upload.com/embed-x50ng81bqkhy.html                                                                                                          
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {}
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5'}                                        
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG -----
2020-08-22 14:01:28 arch anime_downloader.session[84260] DEBUG cached request
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG https://www.mp4upload.com/embed-x50ng81bqkhy.html                                                                                                              
2020-08-22 14:01:28 arch anime_downloader.sites.helpers.request[84260] DEBUG /tmp/animedlm6tlqktt/tmp6fycl4lg
internal/modules/cjs/loader.js:1033
  throw err;
  ^

Error: Cannot find module './lib/main'
Require stack:
- /home/bl/.local/lib/python3.8/site-packages/anime_downloader/node_modules/vm2/index.js
- /home/bl/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1030:15)
    at Function.Module._load (internal/modules/cjs/loader.js:899:27)
    at Module.require (internal/modules/cjs/loader.js:1090:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at Object.<anonymous> (/home/bl/.local/lib/python3.8/site-packages/anime_downloader/node_modules/vm2/index.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:1201:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
    at Module.load (internal/modules/cjs/loader.js:1050:32)
    at Function.Module._load (internal/modules/cjs/loader.js:938:14)
    at Module.require (internal/modules/cjs/loader.js:1090:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/bl/.local/lib/python3.8/site-packages/anime_downloader/node_modules/vm2/index.js',
    '/home/bl/[eval]'
  ]
}
Traceback (most recent call last):
  File "/home/bl/.local/bin/anime", line 8, in <module>
    sys.exit(main())
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/cli.py", line 53, in main
    cli()
  File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/bl/.local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/commands/dl.py", line 120, in command
    for episode in animes:
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 198, in __iter__
    yield episode_class(ep_id[1], parent=self, ep_no=ep_id[0])
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 293, in __init__
    try_data()
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 291, in try_data
    self.source().stream_url
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/extractors/base_extractor.py", line 29, in stream_url
    self.get_data()
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/extractors/base_extractor.py", line 41, in get_data
    data = self._get_data()
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/extractors/mp4upload.py", line 19, in _get_data
    script = util.deobfuscate_packed_js(script)
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/util.py", line 393, in deobfuscate_packed_js
    return eval_in_node('eval=console.log; ' + packedjs)
  File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/util.py", line 403, in eval_in_node
    output = subprocess.check_output(['node', '-e', sandboxedScript], env={'NODE_PATH': node_path})
  File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['node', '-e', "\n                    const {VM} = require('vm2');\n                    const js = Buffer.from('ZXZhbD1jb25zb2xlLmxvZzsgZXZhbChmdW5jdGlvbihwLGEsYyxr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l8ZmFsc2V8cmV0dXJufG9wZW58cGF1c2V8b25jbGlja3xkb3dubG9hZHxnZXRFbGVtZW50QnlJZHxzZ3gzNmZxM3ozYjRxdXVvM293YWV6eXFqNXB5eXVoend2NzZncWJsd2VmbTRreTRrM2l0YWQydHwyODJ8c291cmNlc3xqcGd8MDEyMzl8cG9zdGVyfHRpdGxlfHNvdXJjZScuc3BsaXQoJ3wnKSkpCg==','base64').toString()\n                    console.log(new VM().run(js))\n                    "]' returned non-zero exit status 1.


Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions