Live data from Hacker News

PyPy.js: Python in the web browser

pypyjs.org

61–70 of 129 posts

Re: PyPy.js: Python in the web browser

#61
I'm curious about the virtual filesystem:

  Welcome to PyPy.js!
  >>> import os
  >>> os.listdir('/')
  ['tmp', 'home', 'dev', 'lib']
  >>> f = open('/what', 'w')
  >>> f.write('hey')
  >>> f.close()
  >>> os.listdir('/')
  ['tmp', 'home', 'dev', 'lib', 'what']
  >>> open('/what').read()
  'hey'
What is in the stack that makes that work?

Re: PyPy.js: Python in the web browser

#63

I'm curious about the virtual filesystem: Welcome to PyPy.js! >>> import os >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib'] >>> f = open('/what', 'w') >>> f.write('hey') >>> f.close() >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib', 'what'] >>> open('/what').read() 'hey' What is in the stack that makes that work?

The Emscripten File System API, "The API is inspired by the Linux/POSIX File System API, with each presenting a very similar interface." https://kripken.github.io/emscripten-site/docs/api_reference...

Re: PyPy.js: Python in the web browser

#65

I'm curious about the virtual filesystem: Welcome to PyPy.js! >>> import os >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib'] >>> f = open('/what', 'w') >>> f.write('hey') >>> f.close() >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib', 'what'] >>> open('/what').read() 'hey' What is in the stack that makes that work?

I believe emscripten provides a virtual filesystem interface. Since it's essentially translating/running c it's either hooking through glibc or the syscall interfaces.

Re: PyPy.js: Python in the web browser

#66

I'm curious about the virtual filesystem: Welcome to PyPy.js! >>> import os >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib'] >>> f = open('/what', 'w') >>> f.write('hey') >>> f.close() >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib', 'what'] >>> open('/what').read() 'hey' What is in the stack that makes that work?

The Emscripten File System API, "The API is inspired by the Linux/POSIX File System API, with each presenting a very similar interface." https://kripken.github.io/emscripten-site/docs/api_reference...

Thanks!

Re: PyPy.js: Python in the web browser

#67
post #58
post #44

Didn't we decide a long while back that fully featured programming languages were dangerous in the browser, especially if they could do disk I/O? Even if sandboxed? A la Java Applets and Adobe Flash? import os for subdir, dirs, files in os.walk('./'): for file in files: print file os.remove(file) Perhaps the environment is "fake", and these files don't really exist, even in some sandbox... otherwise, seems like this…

This is Javascript, not real Python. If you're so afraid that this is dangerous, why do you post malicious code? And if you're so clever to post that code, why don't you try similar code to see if it really has access to your files? import os os.listdir('/') The answer, by the way, is no.

> If you're so afraid that this is dangerous, why do you post malicious code?

That's not malicious code... it removes files from a sandbox... you can refresh the page and see for yourself.

> And if you're so clever to post that code

There's no need to be rude... there's an honest question and lack of understanding in my post - educate me, don't talk down to me.

> why don't you try similar code to see if it really has access to your files

The question was if someone could break out of a sandbox, such as with Java Applets and Adobe Flash. I have no idea how to do that - I'm not a security specialist, nor some sort of hacker guy.

> The answer, by the way, is no.

From the sandbox and using the standard `import os`, ya, you're right. The question, again, is what if someone got outside the sandbox?

Re: PyPy.js: Python in the web browser

#68

Earlier quoted context omitted.

I don't know about PyPy.js specifically, but most systems like this provide a virtual filesystem that maps back to things like indexedDB and localstorage which are browser APIs. There is no way that pypy.js is able to access local files on your machine outside of the browser sandbox.

I bet there's a few cheeky hackers around the world who may disagree with that statement. Always assume it's broken.

No, not in this case. It's running in JS land in the browser so any exploits to break out of the browser sandbox using this could be done simpler with raw JS.

Re: PyPy.js: Python in the web browser

#69
post #67
post #58

Earlier quoted context omitted.

This is Javascript, not real Python. If you're so afraid that this is dangerous, why do you post malicious code? And if you're so clever to post that code, why don't you try similar code to see if it really has access to your files? import os os.listdir('/') The answer, by the way, is no.

> If you're so afraid that this is dangerous, why do you post malicious code? That's not malicious code... it removes files from a sandbox... you can refresh the page and see for yourself. > And if you're so clever to post that code There's no need to be rude... there's an honest question and lack of understanding in my post - educate me, don't talk down to me. > why don't you try similar code to see if it really has…

Well why doesn't this apply to JS? The python interpreter is running in the JS sandbox

Re: PyPy.js: Python in the web browser

#70
post #4

Pity it's not Python3.

Yeah weird. I would expect Python2 to be dying off more by now. Wonder if we're headed to an environment where there's essentially 2 separate languages as Python 3 continues to change and grow?

I still get surprises like starting to learn Google Cloud Functions and realizing that up until July of this year they only supported Python 2.

I have no idea why would a project of this caliber would start by using Python 2 instead of Python 3.

Edit: When I started reading about GCF, all docs said I could only use Python 2. Later I found that they seem to be on the way to change this. But still, I was very surprised that Python 2 was even an option to begin with.

Post reply on HN