views:

74

answers:

2

Here is what I would like to do, and I want to know how some people with experience in this field do this:

With three POST requests I get from the http server:

  1. widgets and layout
  2. and then app logic (minimal)
  3. data

Or maybe it's better to combine the first two or all three. I'm thinking of using pyqt. I think I can load .ui files. I can parse json data. I just think it would be rather dangerous to pass code over a network to be executed on the client. If someone can hijack the connection, or can change the apps setting to access a bogus server, that is nasty.

I want to do it this way because it keeps all the clients up-to-date. It's sort of like a webapp but simpler because of Qt. Essentially the "thin" app is just a minimal compiled python file that loads data from a server.

How can I do this without introducing security issues on the client? Is https good enough? Is there a way to get pyqt to run in a sandbox of sorts?

PS. I'm not stuck on Qt or python. I do like the concept though. I don't really want to use Java - server or client side.

+1  A: 

Your desire to send "app logic" from the server to the client without sending "code" is inherently self-contradictory, though you may not realize that yet -- even if the "logic" you're sending is in some simplified ad-hoc "language" (which you don't even think of as a language;-), to all intents and purposes your Python code will be interpreting that language and thereby execute that code. You may "sandbox" things to some extent, but in the end, that's what you're doing.

To avoid hijackings and other tricks, instead, use HTTPS and validate the server's cert in your client: that will protect you from all the problems you're worrying about (if somebody can edit the app enough to defeat the HTTPS cert validation, they can edit it enough to make it run whatever code they want, without any need to send that code from a server;-).

Once you're using https, having the server send Python modules (in source form if you need to support multiple Python versions on the clients, else bytecode is fine) and the client thereby save them to disk and import / reload them, will be just fine. You'll basically be doing a variant of the classic "plugins architecture" where the "plugins" are in fact being sent from the server (instead of being found on disk in a given location).

Alex Martelli
So it would be a waste of time to try an implement some kind of template system or language that would be parsed on the client side rather than executing pure python code? I don't really want the client to be able to do stuff like remove(). Even knowing that it is possible, kind of freaks me out. Since it's essentially similar in behavior to a webapp, would it be possible to attach "actions" to the widgets in the .ui file and have the app interpret the actions? I noticed in Designer I can add dynamic properties. Would dynamic properties be a way to achieve that?
sims
Alex Martelli
I'm worried about slim possibility of a hijack etc. as mentioned above. I want to take a similar stance to browser devs (IE excluded) not to let the app affect the host OS and FS.As I mentioned to Eike, I do not want to show data in a browser. That part of the app is complete and works well.I think I'll go with the dynamic properties. I guess I just need to figure out how to read them once the .ui is loaded. Seeing as you are a python guru, I should probably ask more detailed questions elsewhere. Of course please tell me if my approach is not going to work or if there is a better way.
sims
+1  A: 

Use a web-browser it is a well documented system that does everything you want. It is also relatively fast to create simple graphical applications in a browser. Examples for my reasoning:

  • The Sage math environment has built their graphical client as an application that runs in a browser, together with a local web-server.

  • There is the Pyjamas project that compiles Python to Javascript. This is IMHO worth a try.

Edit:

  • You could try PyPy's sandbox interpreter, as a secure Python interpreter for the code that was transferred over a network.

  • An then there is the most simple solution: Simply send Python modules over the network, but sign and/or encrypt them. This is the way all Linux distributions work. You store a cryptographic token on the local computer. The server signs/encrypts the code before it sends it, with a matching token. GPG should be able to do it.

Eike
The browser is a minefield of gotchas and slow load times. The webapp version of my app is for mobile phones. I want a nice interface for the desktop. I don't want to waste my time on the browser. I did implement a part of the app as AJAX and cool Dijits and all that jazz, and it took approx. 10 times longer than plain HTML forms. Plain HTML forms for the phones, real widgets for the desktop.
sims
Javascript has at least a working sandbox mechanism. As a much more simple solution you could send signed pieces of Python code, similar to what the Linux distributions do. And then there is Pypy's sandbox interpreter.
Eike
Thanks for the info about pypy. I'll look into that.
sims