-
-
Notifications
You must be signed in to change notification settings - Fork 174
Add new LogBox configuration option to disallow serializing complex objectts #615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,6 +31,14 @@ component accessors="true" { | |||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
property name="levelMax"; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Allow Serializing Complex Objects | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
property | ||||||||||||||||||||||||||||||
name ="allowSerializingComplexObjects" | ||||||||||||||||||||||||||||||
type ="boolean" | ||||||||||||||||||||||||||||||
default="true"; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// The log levels enum as a public property | ||||||||||||||||||||||||||||||
this.logLevels = new coldbox.system.logging.LogLevels(); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
@@ -44,14 +52,16 @@ component accessors="true" { | |||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
function init( | ||||||||||||||||||||||||||||||
required category, | ||||||||||||||||||||||||||||||
numeric levelMin = 0, | ||||||||||||||||||||||||||||||
numeric levelMax = 4, | ||||||||||||||||||||||||||||||
struct appenders = {} | ||||||||||||||||||||||||||||||
numeric levelMin = 0, | ||||||||||||||||||||||||||||||
numeric levelMax = 4, | ||||||||||||||||||||||||||||||
struct appenders = {}, | ||||||||||||||||||||||||||||||
boolean allowSerializingComplexObjects = true | ||||||||||||||||||||||||||||||
){ | ||||||||||||||||||||||||||||||
// Save Properties | ||||||||||||||||||||||||||||||
variables.rootLogger = ""; | ||||||||||||||||||||||||||||||
variables.category = arguments.category; | ||||||||||||||||||||||||||||||
variables.appenders = arguments.appenders; | ||||||||||||||||||||||||||||||
variables.rootLogger = ""; | ||||||||||||||||||||||||||||||
variables.category = arguments.category; | ||||||||||||||||||||||||||||||
variables.appenders = arguments.appenders; | ||||||||||||||||||||||||||||||
variables.allowSerializingComplexObjects = arguments.allowSerializingComplexObjects; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// Logger Logging Level defaults, which is wideeeee open! | ||||||||||||||||||||||||||||||
variables.levelMin = arguments.levelMin; | ||||||||||||||||||||||||||||||
|
@@ -326,6 +336,14 @@ component accessors="true" { | |||||||||||||||||||||||||||||
required severity, | ||||||||||||||||||||||||||||||
extraInfo = "" | ||||||||||||||||||||||||||||||
){ | ||||||||||||||||||||||||||||||
if ( !variables.allowSerializingComplexObjects && checkForComplexObjects( arguments.extraInfo ) ) { | ||||||||||||||||||||||||||||||
throw( | ||||||||||||||||||||||||||||||
message = "Attempted to log a complex object in the extraInfo parameter, but it is disallowed.", | ||||||||||||||||||||||||||||||
detail = "Log Message: #arguments.message#; Log Severity: #arguments.severity#", | ||||||||||||||||||||||||||||||
type = "Logger.SerializingComplexObjectException" | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
var target = this; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// Verify severity, if invalid, default to INFO | ||||||||||||||||||||||||||||||
|
@@ -456,4 +474,46 @@ component accessors="true" { | |||||||||||||||||||||||||||||
return canLog( this.logLevels.DEBUG ); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
private boolean function checkForComplexObjects( required any value ){ | ||||||||||||||||||||||||||||||
if ( isNull( arguments.value ) ) { | ||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if ( isSimpleValue( arguments.value ) ) { | ||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// If the object has a $toString() method, then we consider it safe | ||||||||||||||||||||||||||||||
if ( isObject( arguments.value ) AND structKeyExists( arguments.value, "$toString" ) ) { | ||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// CFML Exceptions are safe | ||||||||||||||||||||||||||||||
if ( isCFMLException( arguments.value ) ) { | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the |
||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if ( isArray( arguments.value ) ) { | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In all reality, if we are going to NOT allow anything complex, I would say don't even check for here down, why go through the trouble of iterate through each of the values, this is time consuming, error proned and just slow. |
||||||||||||||||||||||||||||||
return arraySome( arguments.value, function( v ){ | ||||||||||||||||||||||||||||||
return checkForComplexObjects( v ); | ||||||||||||||||||||||||||||||
} ); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if ( isStruct( arguments.value ) ) { | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||||||||||||||||||||||||||||||
return structSome( arguments.value, function( k, v ){ | ||||||||||||||||||||||||||||||
return checkForComplexObjects( v ); | ||||||||||||||||||||||||||||||
Comment on lines
+498
to
+504
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The recursive check for complex objects could cause performance issues with deeply nested or large data structures. Consider adding a depth limit or size limit to prevent excessive recursion that could impact logging performance.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||
} ); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
private boolean function isCFMLException( required any value ){ | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change method name to |
||||||||||||||||||||||||||||||
return ( isObject( arguments.value ) || isStruct( arguments.value ) ) && ( | ||||||||||||||||||||||||||||||
structKeyExists( arguments.value, "stacktrace" ) && | ||||||||||||||||||||||||||||||
structKeyExists( arguments.value, "message" ) && | ||||||||||||||||||||||||||||||
structKeyExists( arguments.value, "detail" ) | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document the function, no excuses now, use chatgpt