Enhancing ColdFusion Script Protection - Security Series #10

本文探讨了ColdFusion脚本保护存在的问题,并提出了改进措施。一方面避免了合法XML被误判为恶意脚本,另一方面增加了对危险的iframe标签的过滤。

From http://www.12robots.com/index.cfm/2008/9/9/Enhancing-ColdFusion-Script-Protection--Security-Series-10

So anyone that has ever turned on Script Protection has either been annoyed by something that it does, or by something that it doesn't do. For me, it was both. I recently spoke with someone at bFlex about it, and he was having some of the same issues I had had with ColdFusion Script Protection. So, I finally decided to dig into it and see what could be done.

 

The Problem

There are two problems with ColdFusion Script Protection:

 

 

  1. It covers too much
  2. It doesn't cover enough

 

Well, that weird, isn't it? Yes, it's true. Script Protection is too strong and too weak at the same time.

 

Too Strong

"Too strong" might no be exactly the right way to describe this behavior in script protection, but this behavior bugs me none-the-less.

 

Let's say that someone tries to inject some Cross-Site Scripting code into the comments section of your blog. Something like:

 


<script type="text/javascript>

alert("pown'd");
</script>

 

Well ColdFusion Script Protection would turn that little diddy into this:

 


<InvalidTag type="text/javascript>
alert("
pown'd");
</script>

 

That's exactly what we want. This part of script protection is great. It would do the same thing with the Object, Embed, Applet, and Meta tags.

Now, let's pretend that someone (maybe even me) wants to put something on my blog about Transfer-ORM configuration files. Which look like this:

 


<?xml version="1.0" encoding="UTF-8"?>
<objectDefinitions>

     <package name="pages">
         <InvalidTag name="page" table="pages">
             <id name="pageid" type="UUID" />
             <property name="pagename" type="string" nullable="false" />
             <property name="pagetitle" type="string" nullable="true" />
            ...
            
             <onetomany name="section" lazy="true">
                 <link to="pages.section" column="fkpageid"/>
                 <collection type="array">
                     <order property="sortno" order="asc"/>
                 </collection>
             </onetomany>
         </object>
        
        ...
</objectDefinitions>
</transfer>

 

Well, you see that <objectDefinitions> tag? It has the pattern "<object" in it. That means Script Protection is gonna see it as a threat.

So my Transfer config example is going to look like this.

 


<?xml version="1.0" encoding="UTF-8"?>
<InvalidTagDefinitions>
...
</objectDefinitions>

 

That sucks. And since the <objectDefinitions> is harmless when displayed, there is no reason for it to get filter like this.

This is the same issue that I heard about at bFlex, though a different tag was being filtered.

 

Too Weak

ColdFusion Script Protection is also too weak. It does not catch enough troublesome scripts. One of the biggies that it doesn't get, and I really can't understand why, is <iframe>.

 

IFrames are incredibly dangerous and can be used for some pretty nefarious stuff. Granted, if you are properly escaping your user-generated output with HTMLEditFormat() this shouldn't be a concern, but it is a dangerous assumption to believe we are perfect. There may be some other tags or patterns we would like to see removed as well.

 

The Solution

So, it turns out that changing this behavior in ColdFusion Script Protection is pretty easy. There is an XML config file that contains patterns that are compared to the incoming data. If a match is made, then the replacement value is inserted. The patterns are simple Regular Expressions (RegEx).

 

So not being an expert in Regular Expressions, I asked Ben Nadel to help me figure this out. He helped me find the RegEx solution I needed very quickly. Thanks Ben!

In your ColdFusion installation you will find a /lib folder.

Windows users: C:/ColdFusion8/lib Mac Users: /Applications/ColdFusion/lib *nix: /opt/coldfusion/lib (I think)

In the /lib folder you will find a file called neo-security.xml. Near the bottom of this file you'll see something that looks like:

 


    <var name='CrossSiteScriptPatterns'>
        <struct type='coldfusion.server.ConfigMap'>
            <var name='</s*(object|embed|script|applet|meta)'>
                <string>
                    <InvalidTag
                </string>
            </var>
        </struct>
    </var>

 

What this is saying is, if you come across something that matches the RegEx Pattern "&lt;/s*(object|embed|script|applet|meta)", then replace those characters with &lt;InvalidTag.

Now, normally I would think that this is fine, but like I said, I do not want <objectDefinition to be turned into <InvalidTagDefinition.

So, how do I stop this? Well first, I take the "object" text out of the existing patterns and make a new pattern with it. And I add a little extra.

 


    <var name='CrossSiteScriptPatterns'>
        <struct type='coldfusion.server.ConfigMap'>
            <var name='</s*(embed|script|applet|meta)'>
                <string>
                    <InvalidTag
                </string>
            </var>
            <var name='</s*object(?!Definitions)'>
                <string>
                    <InvalidTag
                </string>
            </var>
        </struct>
    </var>

 

So here, I have added another pattern for the XSS filter to try to match. This patterns says to match <object unless it is <objectDefinitions.

This could also be expanded to include additional patterns that begin with "<object".

 


    <var name='CrossSiteScriptPatterns'>
        <struct type='coldfusion.server.ConfigMap'>
            <var name='</s*(embed|script|applet|meta)'>
                <string>
                    <InvalidTag
                </string>
            </var>
            <var name='</s*object(?!(Definitions|ive))'>
                <string>
                    <InvalidTag
                </string>
            </var>
        </struct>
    </var>

 

Here, it will not match "<objectDefinitions" or "<objective".

Very nice.

Now to discuss adding the <iframe> tag. This is actually even easier.

 


    <var name='CrossSiteScriptPatterns'>
        <struct type='coldfusion.server.ConfigMap'>
            <var name='</s*(embed|script|applet|meta)'>
                <string>
                    <InvalidTag
                </string>
            </var>
            <var name='</s*object(?!(Definitions|ive))'>
                <string>
                    <InvalidTag
                </string>
            </var>
            <var name='</s*iframe'>
                <string>
                    <InvalidTag
                </string>
            </var>
        </struct>
    </var>

 

Simply by adding another <var> to the <struct> I can add this pattern "&lt;/s*iframe" which will find <iframe.

UPDATE: I forgot to mention in this post, after you change the neo-security.xml that you must restart the ColdFusion Application Server for the changes to take effect.

### Python代码功能解析 以下是针对用户提供代码的功能分解,重点在于所涉及的库、函数调用以及生成图表的意义。 --- #### **1. 库的作用** - #### `headm` 此模块可能是项目内部开发的一个通用头文件管理器,负责加载其他依赖项或初始化全局环境。虽然具体实现未知,但从命名习惯推测,它可能包含了诸如日志记录、常量定义等功能[^1]。 - #### `tsvisa` 和 `tsstm32` - `tsvisa`: 可能基于NI-VISA (Virtual Instrument Software Architecture),用于控制测试与测量设备间的通信协议栈。这允许脚本直接操控外部硬件资源,比如电源供应单元PSU或是示波器Oscilloscope等电子装置。 - `tsstm32`: 或许封装了一些专门面向STM32微控制器系列的操作接口,便于嵌入式系统的调试和监控工作流自动化。 --- #### **2. 主要函数详解** - #### `dm3068open()` 功能:开启并配置DM3068数字万用表(DMM),使其进入准备状态接受指令集输入。假设这是一个虚拟仪器驱动层面上的方法,则其典型行为包括但不限于: - 设定默认精度等级; - 清零缓冲区以防止残留干扰信号影响新测得的结果准确性; - 同步时钟源确保跨平台间一致性表现良好。 ```python def dm3068open(): """Initialize and open DM3068 DMM.""" dmm = initialize_digital_multimeter(model=&#39;DM3068&#39;) set_default_settings(dmm) clear_buffer(dmm) sync_clocks(dmm) return dmm ``` - #### `dh1766volt1(value)` 描述:向DH1766直流稳压源发送命令更改输出电平至指定值,并等待一段时间让电路稳定下来再继续下一步动作。这里假定了存在某种形式的时间延迟机制保障每次修改后的充分反应周期完成之后才去读取新的反馈信息回来评估效果如何。 ```python def dh1766volt1(voltage_level): """Set DH1766 PSU output to given voltage level.""" psu = get_power_supply_unit() send_command(psu, f&#39;SET_VOLTAGE {voltage_level}&#39;) wait_for_stabilization(duration=2) # Wait for stabilization period. ``` - #### `meterval()` 定义:查询当前连接的所有计量仪表的状态返回一组元组列表,其中每个元素代表单独一台设备上的即时读数。例如,在我们的场景下只关心第一个位置处存储的实际负载两端差动势能大小即伏特计数值。 ```python def meterval(): """Retrieve readings from all connected meters.""" meters = list_connected_meters() values = [read_meter(meter) for meter in meters] return tuple(values) ``` - #### `tspsave(...)` 表达意义:持久保存实验过程中产生的各类动态变化轨迹数据到本地磁盘文件当中形成永久档案资料方便日后查阅对比研究用途。参数分别指明了类别标签名称以及对应维度数组容器实例对象本身。 ```python def tspsave(label, **kwargs): """Save time-series data with labels into storage.""" filename = generate_unique_filename(prefix=label) save_to_disk(filename, kwargs) ``` --- #### **3. 图表生成过程解读** 最终绘制的是一个描述电流随施加电压线性增长趋势的关系曲线图。横轴标注为“Current(A)”表示安培单位下的瞬态流动强度;纵轴标记成“Voltage(V)”则反映相应条件下维持该流量所需付出的能量代价——也就是常说的工作电压水平。 通过遍历预设范围内的不同电压级别逐步累积起来的经验观测点位集合构成了散点阵列基础素材,经由Matplotlib绘图引擎渲染加工后呈现出直观可视化的二维平面几何形态特征出来供观察者快速把握整体规律走向特点所在之处。 ```python import matplotlib.pyplot as plt # Plotting the I-V characteristic curve plt.figure(figsize=(8, 6)) plt.plot(idim, odim, color=&#39;blue&#39;, linewidth=3, label="Measured Data") # Adding titles & labels plt.title("I-V Characteristic Curve", fontsize=16) plt.xlabel("Current (A)", fontsize=14) plt.ylabel("Voltage (V)", fontsize=14) # Enhancing readability plt.legend(fontsize=12) plt.grid(True, linestyle=&#39;--&#39;, alpha=0.7) plt.tight_layout() # Display plot plt.show() ``` --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值