I think most ColdFusion developers will agree that the CFDump tag, and its writeDump() counterpart, have made debugging CFML code a joyful part of the software development life-cycle. I know I have. But, in recent years, I've run into some consistent points of friction.
View this code in my Dump4CSP project on GitHub.
For starters, Adobe sets the font-size of the CFDump output to xx-small; which is absurdly small for my rapidly aging eyeballs. I'm at a point in my life where I need all fonts to be at least 16px, if not 18px depending on how tired I am.
But font sizes can be overridden in my site's CSS. What I can't "override" is the fact that the native CFDump tag implementation uses inline JavaScript tags and inline onclick handlers — both of which are rejected by my site's Content Security Policy (CSP). This leaves the rendered CFDump output readable but not interactive.
Not to mention the fact that every time I render a CFDump output on my site, the browser reports a CSP violation to my error logging.
In what I assumed would be a quick experiment, I decided to write my own implementation of the CFDump tag. But this "quick experiment" turned into a two-week deep-dive of data structures, value reflection, and highly opinionated trade-offs.
What I ended up with was Dump4CSP - a ColdFusion custom tag implementation of the dump algorithm. This implementation brings a lot of my opinions with it:
-
It uses the browser's native
<details>disclosure controls such that collapsing part of the rendered tree needs no JavaScript. The trade-off is that collapsing only applies vertically, not horizontally. -
It wraps most of the CSS selectors in
:where()to keep specificity flat at(0,1,0). This means that overriding parts of the render styling needs a single CSS class selector. And, you can even supply a custom CSS class to the rendered wrapper. -
It styles the fonts and colors of the various data structures using CSS custom properties, all defined on the root wrapper. Which makes it easy to tweak the output.
-
It provides more attributes to control the output limits; and even side-steps a few bugs in Adobe ColdFusion's implementation (such as max-depth recursion on Arrays and Sets, which currently cause Stack Overflow errors in ACF 2025).
To read more about the input attributes, you can see the Dump4CSP readme on GitHub. But you invoke the Dump4CSP tag the same way that you would the CFDump tag. Only, you have to provide the template path explicitly:
<cfscript>
data = [
id: 4,
name: "Ben Nadel",
favoriteFoods: [
[ name: "Pizza", rating: 4.8 ],
[ name: "General Tso's Chicken", rating: 5 ],
[ name: "Chicken Wings", rating: 4 ],
[ name: "Pumpkin Pie", rating: 4.7 ],
],
personality: setNew([ "Cautious", "Joyful", "Easy Going", "Cuddly" ])
];
cfmodule(
template = "./dump4csp/dump4csp.cfm",
var = data,
label = "Dump4CSP Demo"
);
</cfscript>
Running this ColdFusion code gives us the following output:
Of course, you can always create a CFScript-based helper function for even easier invocation (and encapsulation of the custom tag path):
<cfscript>
data = [
// ... data truncated ...
];
dump4csp(
var = data,
label = "Dump4CSP Demo (CFScript)"
);
// ------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------- //
/**
* I provide a CFScript-based wrapper for the dump4csp.cfm ColdFusion custom tag. This
* hides the custom tag path for developer convenience.
*/
private void function dump4csp( any var ) {
cfmodule(
template = "./dump4csp/dump4csp.cfm",
var = arguments?.var,
attributeCollection = arguments
);
}
</cfscript>
Anyway, I just published this implementation yesterday and only finally integrated it into my blog's local development last night. So, I'm sure I'll still be working out bugs and fine-tuning the rendering process. But the font-size alone is a huge win for me personally. For the rest of you, your mileage may vary!
Reader Comments
Loved the video walk through. Always enjoy them. And wow, this is an impressive amount of effort you've put into this.
Would it also have been possible to loosen your CSP for dumped elements?
@Chris,
The CSP is supplied as an HTTP header (or
<meta>tag equivalent) and applies to the whole page. I don't believe there's a way to weaken it for just a portion of the page. Plus, if I could, I wouldn't be able to fall down rabbit-hole like this one 🤪I've encountered this in the past and have written a couple of different cfTag-based dump alternatives. One of the updates was to identify & prevent sensitive credit card numbers from being displayed when a customer was filling out a feedback or contact form.
(I wish Adobe would invest some time and modernize this built-in function.)
I blogged about an open-source alternative 2 years ago... cf_dump by Alexander Kwaschny and some new options have been added since. Enjoy!
https://dev.to/gamesover/coldfusion-dump-alternative-347b
This reminds me of Ray Camden's post from Oct 6, 2010:
Can't dump? Try a fake dump.
@James,
I was shocked by how much effort I ended up putting into this thing. When I started, I was like, "Oh yeah, this will probably take 2-3 hours"; and then I kept hitting little details I wasn't sure about; and edge-cases I hadn't considered. Which I guess is really what makes the original
CFDumptag so amazing — that it hid soooo much complexity from us and just made debugging a joy.But to your point, and my point, a little modernization wouldn't hurt. Especially given the fact that ColdFusion now ships with built-in CSP functionality, which the
CFDumpoutput doesn't even take into account.As far as including the data-type in the output (one of the things you call-out in the linked post) - I went back and forth on that. I like it in Lucee; but sometimes it feels like more than I need. I considered making it an optional setting. But I was already like 2-weeks into a 3-hour project 😜
@Phillip,
It's just crazy how long we've (the ColdFusion community) has been loving on the
CFDumptag. It truly feels unmatched in other languages.Post A Comment — ❤️ I'd Love To Hear From You! ❤️
Post a Comment →