Re: [Python-de] bottle-template: syntax error
Peter Otten wrote:
(und bottle verwendet eval() für templates):
Ist eval() speziell in Web-Anwendungen nicht ziemlich unangebracht - insbesondere beim Rendering von Web-Seiten, welche wiederrum Benutzereingaben enthalten können? Ciao, Michael.
Michael Ströder wrote:
Peter Otten wrote:
(und bottle verwendet eval() für templates):
Ist eval() speziell in Web-Anwendungen nicht ziemlich unangebracht - insbesondere beim Rendering von Web-Seiten, welche wiederrum Benutzereingaben enthalten können?
Das heißt nur, dass du die Templates genauso vor dem Zugriff Unbefugter schützen musst wie den übrigen Python-Code. Gefährlich wird's natürlich, wenn das Template wiederum ein eval() enthält, das Anwendereingaben verarbeitet. Das ist wiederum nicht anders als bei "normalem" Python-Code.
Am Tue, 03 Sep 2013 09:24:49 +0200 schrieb Michael Ströder <michael@stroeder.com>:
Peter Otten wrote:
(und bottle verwendet eval() für templates): Ist eval() speziell in Web-Anwendungen nicht ziemlich unangebracht - insbesondere beim Rendering von Web-Seiten, welche wiederrum Benutzereingaben enthalten können?
Nein, wieso? Damit kann man doch schöne Sachen machen! Damit können die Nutzer ihre eigenen python-Befehle in Formularfelder einfügen und der Server führt die dann aus. :-) Viel Spaß, Arnold
On 03.09.2013 09:24, Michael Ströder wrote:
Peter Otten wrote:
(und bottle verwendet eval() für templates):
Ist eval() speziell in Web-Anwendungen nicht ziemlich unangebracht - insbesondere beim Rendering von Web-Seiten, welche wiederrum Benutzereingaben enthalten können?
Es wäre für mich auf jeden Fall ein weiterer Grund (neben anderen Erwägungen, wie mehr Features etc.), gleich eine zusätzliche Template-Engine, wie z.B. Jinja2, mit bottle zu verwenden. Chris
On 03.09.2013 14:52, Christopher Arndt wrote:
On 03.09.2013 09:24, Michael Ströder wrote:
Peter Otten wrote:
(und bottle verwendet eval() für templates): Ist eval() speziell in Web-Anwendungen nicht ziemlich unangebracht - insbesondere beim Rendering von Web-Seiten, welche wiederrum Benutzereingaben enthalten können? Es wäre für mich auf jeden Fall ein weiterer Grund (neben anderen Erwägungen, wie mehr Features etc.), gleich eine zusätzliche Template-Engine, wie z.B. Jinja2, mit bottle zu verwenden.
Um das mal klar zu stellen: (Fast) jede Template Engine übersetzt Template Code in Python Code und jagt den durch eval(). Auch Jinja2, Mako, Cheeta und Andere. Das ist die einzige möglichkeit, einigermaßen schnelle Templates zu bekommen. Template Dateien sind vom Sicherheitsaspekt her ausführbare Programme. Wenn im Template Schadcode steht, dann wird der auch ausgeführt. Daher sollte man Benutzern nie erlauben, eigene Templates hoch zu laden, genau so wie es eine doofe Idee ist, Python code ungeprüft auf dem Server aus zu führen. Die Benutzer-Eingaben, die in ein Template hinein gerendert sind, sind etwas völlig anderes. Die werden nicht ausgeführt oder durch eval() gejagt. Das ist bei keiner Template Engine so, das wäre ja auch reichlich blöd.
On 03.09.13 15:56, Marcel Hellkamp wrote:
On 03.09.2013 14:52, Christopher Arndt wrote:
On 03.09.2013 09:24, Michael Ströder wrote:
Peter Otten wrote:
(und bottle verwendet eval() für templates): Ist eval() speziell in Web-Anwendungen nicht ziemlich unangebracht - insbesondere beim Rendering von Web-Seiten, welche wiederrum Benutzereingaben enthalten können? Es wäre für mich auf jeden Fall ein weiterer Grund (neben anderen Erwägungen, wie mehr Features etc.), gleich eine zusätzliche Template-Engine, wie z.B. Jinja2, mit bottle zu verwenden.
Um das mal klar zu stellen:
(Fast) jede Template Engine übersetzt Template Code in Python Code und jagt den durch eval(). Auch Jinja2, Mako, Cheeta und Andere. Das ist die einzige möglichkeit, einigermaßen schnelle Templates zu bekommen.
Ich schraube gerade an einer Templating-Sprache rum, die genau das nicht tut: http://www.livinglogic.de/Python/ul4c/Howto.html Templates werden hier nicht in Python-Code umgewandelt, sondern von einem Compiler kompiliert. Damit kann man dann auch dem Kunden erlauben, selber Templates zu bauen, weil er keine bösen Dinge tun kann (naja, außer evtl. Endlosschleifen bauen).
Template Dateien sind vom Sicherheitsaspekt her ausführbare Programme. Wenn im Template Schadcode steht, dann wird der auch ausgeführt. Daher sollte man Benutzern nie erlauben, eigene Templates hoch zu laden, genau so wie es eine doofe Idee ist, Python code ungeprüft auf dem Server aus zu führen.
[...]
Servus, Walter
participants (6)
-
Arnold Krille
-
Christopher Arndt
-
Marcel Hellkamp
-
Michael Ströder
-
Peter Otten
-
Walter Dörwald