My Own Python Web Framework

by healeycodeson 2/22/2023, 2:12 PMwith 18 comments

by ptxon 2/22/2023, 8:35 PM

This API looks like a recipe for XSS vulnerabilities:

  def render(data):
      return f"<h1>Last regenerated at: {data['time']}</h1>", {}
What if data['time'] is '<script>alert("oops!")</script>'?

While JavaScript's template literals [1] would allow this kind of API to work (because the prefix of the template string can be a function that escapes the parameters), Python's f-strings doesn't have equivalent functionality. The tuple returned from the render function should probably include an additional item containing the parameters for the format string (which shouldn't be an f-string).

See also [2].

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[2] https://en.wikipedia.org/wiki/Uncontrolled_format_string

by nickpetersonon 2/22/2023, 5:53 PM

I feel the time is ripe for a programming called spider so we can have a spider web framework.

by geenaton 2/22/2023, 7:52 PM

How is HTML syntax highlighting in strings?