Making user-made HTML templates safe

后端 未结 4 1890
野的像风
野的像风 2021-01-06 16:32

I want to allow users to create tiny templates that I then render in Django with a predefined context. I am assuming the Django rendering is safe (I asked a question about t

4条回答
  •  粉色の甜心
    2021-01-06 16:54

    You are overlooking server side security issues. You need to be very careful that users can't use the templates import or include mechanism to access files they don't have permission to.

    The bigger challenge is to prevent the template system from infinite loops and recursion. This is an obvious threat to system performance, but depending on the implementation and deployment setup, the server may never timeout. With a finite number of python threads at your disposal, repeated calls to a misbehaving template could quickly bring your site down.

提交回复
热议问题