Zaw Aung's Blog

POV-Ray in the browser, without letting strangers run code

POV-Ray Online is a page where you paste a scene or upload a .pov file, press Render, and watch a ray-traced image appear. It is about 350 lines in total: a FastAPI back end that runs the real povray program, and one static HTML page.

The interesting problem

A POV-Ray scene is not just data, it is a program. The scene language can read and write files and (unless told not to) run shell commands. Putting a renderer on the public internet is therefore the same as letting strangers run code on your server, and most of the work here is making that safe.

How a render works

  1. The page posts the scene, a size (320×240, 640×480 or 1024×768) and a quality (Draft, Good or Best).
  2. The server saves the scene in a job folder named by a random 128-bit ID and puts the job on a queue.
  3. A single worker thread takes jobs one at a time and runs povray on them.
  4. The page polls for status. Progress comes from reading POV-Ray’s console output as it is produced and matching its “Rendered N of M pixels” lines, so the progress bar and live log are real, not faked.
  5. When it finishes, the page fetches the PNG.

The sandbox

Several independent layers, so that one mistake does not undo the rest:

Job IDs are validated against a strict pattern before any file path is built from them, which closes off path tricks like ../.

Limits

Comments

Leave a comment

Comments are held for moderation before they appear.