I'm working on a recursive algorithm using ColdFusion custom tags and I ran into a strange bug. It seems that in Adobe ColdFusion 2025 (update 14 at the time of this writing), if you use attributeCollection to "spread" a struct into a custom tag with no other data attributes, any changes made to the attributes scope internally to the custom tag get applied directly to the passed-in struct. This means that mutations to the attributes scope can leak into the calling context.
To demonstrate, let's create a ColdFusion custom tag - myTag.cfm - that does nothing but add two keys to the attributes scope:
<cfscript>
// Mutate attributes via indirect param.
param name="attributes.addedViaParam" type="string" default="Leak";
// Mutate attributes via direct assignment.
attributes.addedViaAssignment = "Leak";
</cfscript>
Now, let's invoke this custom tag twice using the attributeCollection semantics. In the first invocation, we'll pass nothing but the given scope. In the second invocation, we'll pass the given scope plus an additional attribute:
<cfscript>
structA = {};
structB = {};
// ------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------- //
// AttributeCollection is the ONLY input to the custom tag.
cfmodule(
template = "./myTag.cfm",
attributeCollection = structA,
);
// AttributeCollection is ONE OF the inputs to the custom tag.
cfmodule(
template = "./myTag.cfm",
attributeCollection = structB,
otherAttribute = "[content]"
);
// ------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------- //
writeDump( structA );
writeDump( structB );
</cfscript>
In both cases, we'd expect the writeDump() to result in an empty struct. However, when we run this CFML code, we get the following output:
As you can see, the two attributes scope mutations in the first invocation have leaked out of the custom tag context and into the struct that was used to provide the custom tag attributes. But, as we can see from the second invocation, this only happens when the attributeCollection is the only mechanics for providing attribute data.
Reader Comments
I've filed a bug in the Adobe Tracker for this:
CF-4235735: Struct used in
AttributeCollectiongets corrupted when it's the only attribute(s) present.Post A Comment — ❤️ I'd Love To Hear From You! ❤️
Post a Comment →