【问题标题】:Is allowing user input in python's format() a security risk? [duplicate]允许用户以 python 的 format() 格式输入是否存在安全风险? [复制]
【发布时间】:2018-03-13 17:39:37
【问题描述】:

格式化用户使用 Python 的 format() 函数输入的任何字符串是否有风险,参数/值也来自用户输入? (例如user_input_string.format(*user_input_args)

【问题讨论】:

  • 定义有风险的...
  • @JeremyMcGibbon 谢谢,我在搜索时没有找到这个。

标签: python python-3.x security string-formatting user-input


【解决方案1】:

操作本身没有风险,如果用户输入 Python vaid 表达式 - 这不是 eval ed。

如果结果打算进入 SQL 数据库,您应该考虑在构建 SQL 字符串之前引用它。

【讨论】:

  • 这个答案是不正确的并且有潜在的危险。见here
  • 啊,我没有注意到user_input_string 并且格式化模板在我的脑海中是硬编码的。无论如何,模板字符串通常不应该由最终用户提供。
猜你喜欢
  • 2012-02-18
  • 1970-01-01
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多