CFDUMP标签是否可修改?

5

使用ColdFusion MX7,如果我们遇到异常,我们会向开发团队发送电子邮件,其中包含各种数据范围的转储,包括表单结构。

这对于调试非常有用,但在用户登录时出现错误的情况下除外。我们最终会打印出密码。

所以问题是,是否有一种方法可以修改CFDUMP文件,以使其从表单对象中过滤掉密码值?

当然,我们可以将其放入发送电子邮件的相同代码中,但最好将其放入CFDUMP文件中,这样我们就不必担心它会出现在其他地方。

我已经找到了CFDUMP文件,似乎它是二进制的,所以我猜我们无法做到。


即使您使用CF8,也不会真正解决您的问题,但值得注意的是:<cfdump var="#form#" hide="password"> :-) - Patrick McElhaney
4个回答

6

您可以将dump.cfm文件复制到dumporiginal.cfm,然后创建一个新的dump.cfm文件来调用dumporiginal.cfm。

<!--- 
  So that it won't execute twice if you 
  have a closing slash (<cfdump ... />) 
---> 
<cfif thisTag.executionMode neq "start">
  <cfexit method="exitTag" />
</cfif>


<!--- 
  defaults for optional attributes, taken from the docs 
  http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_d-e_08.html
--->
<cfparam name="attributes.expand" default="yes" />
<cfparam name="attributes.format" default="html" />     
<cfparam name="attributes.hide" default="all" />     
<cfparam name="attributes.keys" default="9999" />     
<cfparam name="attributes.label" default="" />      
<cfparam name="attributes.metainfo" default="yes" />     
<cfparam name="attributes.output" default="browser" />     
<cfparam name="attributes.show" default="all" />     
<cfparam name="attributes.showUDFs" default="yes" />     
<cfparam name="attributes.top" default="9999" />     

<!--- Hide the password, but store its value to put it back at the end --->
<cfif isStruct(attributes.var) and structKeyExists(attributes.var, 'password')>
  <cfset originalPassword = attributes.var.password />
  <cfset attributes.var.password = "{hidden by customized cfdump}"/>
</cfif>   

<!--- 
   Call the original cfdump. 
   Which attributes you pass depends on CF version. 
--->              
<cfswitch expression="#listFirst(server.coldfusion.productVersion)#">
<cfcase value="6">
  <cfdumporiginal 
      var = "#attributes.var#"
      expand = "#attributes.expand#" 
      hide = "#attributes.hide#"
      label = "#attributes.label#"
      >
</cfcase>
<cfcase value="7">
  <cfdumporiginal 
      var = "#attributes.var#"
      expand = "#attributes.expand#" 
      hide = "#attributes.hide#"
      label = "#attributes.label#"
      top = "#attributes.top#"
      >
</cfcase>  
<cfdefaultcase>     
  <cfdumporiginal 
      var = "#attributes.var#"
      expand = "#attributes.expand#" 
      format = "#attributes.format#"
      hide = "#attributes.hide#"
      keys = "#attributes.keys#"
      label = "#attributes.label#"
      metainfo = "#attributes.metainfo#"
      output = "#attributes.output#"
      show = "#attributes.show#"
      showUDFs = "#attributes.showUDFs#"
      top = "#attributes.top#"
      >
</cfdefaultcase>
</cfswitch>

<!--- Restore the password, in case it's read after cfdump call ---> 
<cfif isDefined("originalPassword")>
  <cfset attributes.var.password = originalPassword />
</cfif>

我只在CF8中进行了测试,但理论上它应该适用于CF6/7/8+。 - Patrick McElhaney
顺便说一句,在我的机器上(OS X 上的 CF8 开发者版),我在 /Applications/ColdFusion8/wwwroot/WEB-INF/cftags 找到了 dump.cfm。 - Patrick McElhaney

3

不,我认为没有一种方法可以修改的行为。显然我不能确定。虽然这样的黑客存在是可以想象的,但并不一定值得推荐。

为什么不使用一个简单的:

<cftry>
  <cfset DoSomethingThatFails()>

  <cfcatch>
    <cfif StructKeyExists(FORM, "Password")>
      <cfset FORM.Password = "***">
    </cfif>
    <cfdump var="#FORM#">
  </cfcatch>
</cftry>

这也是我的猜测。原因基本上是为了在意料之外的情况下进行替换。如果有人只是为了测试或其他什么事情而随便插入一些内容。 - Tom Hubbard
哦,你的例子实际上改变了密码的值,这可能不是一个问题,因为它在错误情况下。不过最好先复制结构体。 - Tom Hubbard
是的,主要是为了让我的观点更清晰明了。在我看来,如果你不能信任维护系统的人,那么你就完蛋了。 - Tomalak

1

CFDUMP 最初是在 CF5 时期作为自定义标签 (CF_DUMP) 出现的。您始终可以获取该自定义标签的代码并根据您的需求进行修改,然后使用它来替代内置标签。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接