solarwinds / appoptics-apm-node

AppOptics APM Instrumentation Agent for Node.js
Apache License 2.0
11 stars 9 forks source link

NH-13411-Add-SQL-Sanitization-Code #264

Closed ronilan closed 2 years ago

ronilan commented 2 years ago

Overview

This pull request adds SQL Sanitization functionality to the agent.

Status

SQL sanitazation (in this context) is the removal of user data from query strings (e.g. removing Jake and 13 from SELECT * FROM users WHERE name = 'Jake' AND age > 13).

Sanitization was added to the agent via the bindings. It is an FSM written in C++ "copied" from PHP agent.

The Ruby Agent uses a simple regex to achieve similar (but not identical) results.

Change

Notes

cheempz commented 2 years ago

Thanks for the PR writeup @ronilan. I haven't reviewed but these two points are concerning:

All six probes originally used the OBOE_SQLSANITIZE_KEEPDOUBLE option. There no such "option" anymore (again following ruby agent lead). SQL Sanitizer implementation always keeps double quoted data. The is no user customization of the sanitization function (departing from ruby agent lead).

Our spec for sanitization https://github.com/librato/trace/blob/master/docs/specs/sql-sanitization.md has the rationale why there is the option to treat double rather than single quote values as sanitization targets. Quick look in OTel Java they dealt with the same concern and this PR has some good examples: https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/4593

With our Ruby agent the ability to customize the regex could provide a workaround (although ideally the agent should offer a configurable alternatative), but if we remove this for the Node.js agent there would be no recourse.

Side note, our spec has links to some original discussion on why FSM vs. regex, afaict it was to not require multiple regex passes. But it was also unclear whether a custom FSM would be more performant, and given the maintenance/readability trade off I think we can consider multiple regex passes if needed.

ronilan commented 2 years ago

I haven't reviewed but these two points are concerning:

It's easy.

I don't really see any reason for concern (other than in archeological terms), but if it is, let's "Just NOT Do It!" Either this PR, and https://github.com/appoptics/appoptics-bindings-node/pull/117, are merged, or, they are closed. Any further discussion of this feature is moot and a time well wasted.