Skip to main content
Ben Nadel at CFUNITED 2010 (Landsdown, VA) with: Adam Tuttle and Laura Arguello
Ben Nadel at CFUNITED 2010 (Landsdown, VA) with: Adam Tuttle Laura Arguello

Dump4CSP: A ColdFusion Dump Compatible With My Content Security Policy

By
Published in — Comments (1)

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:

Screenshot of the Dump4CSP output, looking very much like native CFDump, only bigger fonts and more readable.

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!

Want to use code from this post? Check out the license.

Reader Comments

328 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?

Post A Comment — I'd Love To Hear From You!

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
— Ben Nadel
Managed ColdFusion hosting services provided by:
xByte Cloud Logo