Server Questions (2 of them)

A

Andrew

Hello List,

How to do you create a server that accepts a set of user code?

For example,

I would like to send this function:
def addition(x,y):
return x+y
and have the socket server perform the operation and send is back to
the end user.

Question 2:
On that same server, I want a user to be able to pass a file to the
server along with code. What is the best way to pass file to the
server?


Thank you for any suggestions or resources you can provide.

Andrew
 
C

Chris Angelico

Hello List,

How to do you create a server that accepts a set of user code?

For example,

I would like to send this function:
def addition(x,y):
  return x+y
and have the socket server perform the operation and send is back to
the end user.

Question 2:
On that same server, I want a user to be able to pass a file to the
server along with code.  What is the best way to pass file to the
server?

The easiest way is to write an HTTP server (Python has some tools that
will make this easy) and use an HTML form, which can do file uploads
as well as accept keyed-in code.

However, you will run into some fairly major security issues. You're
accepting code across the internet and running it. Python does not
protect you against malicious users reading files from your hard disk
or, worse, modifying those files. This sort of thing can ONLY be used
in a trusted environment - a local network on which you know
everything that's happening.

ChrisA
 
H

Hrvoje Niksic

Andrew said:
How to do you create a server that accepts a set of user code?
[...]

Look up the "exec" statement, the server can use it to execute any code
received from the client as a string.

Note "any code", though; exec runs in no sandbox and if a malicious
client defines addition(1, 2) to execute os.system('sudo rm -rf /'), the
server will happily do just that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top