【问题标题】:How do you protect css id你如何保护css id
【发布时间】:2015-12-22 17:53:04
【问题描述】:

我有一个值,最终将是一个 html id= 属性。我无法控制值的设置,因此它可能不安全。我知道检查单引号和双引号,但我应该检查以确保它干净吗?

                                variables.result &= '<div class="alert alert-danger"';
if(attributes.id        != "")  variables.result &= ' id="#attributes.id#"';

【问题讨论】:

  • 搜索转义 html(属性)。那么不管它是什么.. 但是攻击者仍然可以隐藏 id。
  • 不确定我是否明白你想要什么,但我的猜测是:' id="#encodeForHtmlAttribute(attributes.id)#"'
  • 这也适用于风格和类吗?
  • 不要担心要过滤掉什么,而是决定你想要允许什么,并使用正则表达式来限制这些字符的输入。
  • @JamesAMohler 是的,它会转义所有会“离开”标签属性的字符。但请记住,这是为了清理输入,而不是验证。人们仍然可以提交无效的 id 和类(包含规范不允许的坏字符)。这不会是安全问题,但这些值将毫无用处。

标签: coldfusion sanitization coldfusion-11


【解决方案1】:

如果使用 ColdFusion 生成变量名,您可以使用 Inflector CFC 的“variablise”方法。它将任何字符串转换为可用作 ColdFusion 变量名称的安全下划线分隔列表。 (Inflector 基于 Ruby on Rails ActiveSupport::Inflector 类。)

https://github.com/timblair/coldfusion-inflector

<cffunction name="variablise" access="public" returntype="string" output="no" hint="Converts a string to a variable name, e.g. CamelCase becomes camel_case, 'big CSSDogThing' becomes big_css_dog_thing etc.">
    <cfargument name="string" type="string" required="yes" hint="The string to variablise">
    <cfset arguments.string = replace(trim(rereplace(arguments.string, "([^[:alnum:]_-]+)", " ", "ALL")), " ", "-", "ALL")>
    <cfset arguments.string = rereplace(arguments.string, "([A-Z]+)([A-Z][a-z])", "\1_\2", "ALL")>
    <cfset arguments.string = rereplace(arguments.string, "([a-z\d])([A-Z])", "\1_\2", "ALL")>
    <cfreturn lcase(replace(arguments.string, "-", "_", "ALL"))>
</cffunction>

【讨论】:

    【解决方案2】:

    如果我对您的理解正确,那么这可能就是您要查找的内容:

    http://code.google.com/p/google-caja/wiki/JsHtmlSanitizer

    编辑:在 PHP 中:

    What's the best method for sanitizing user input with PHP?

    EDIT2:没看到你在使用coldfusion,也许就是这样:

    Cleansing string / input in Coldfusion 9

    【讨论】:

    • 这看起来像一个客户端工具。我正在寻找服务器端解决方案
    猜你喜欢
    • 1970-01-01
    • 2017-03-13
    • 2013-06-25
    • 1970-01-01
    • 2011-07-23
    • 2014-08-07
    • 1970-01-01
    • 2020-01-29
    • 2016-12-18
    相关资源
    最近更新 更多