-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
hubble: escape terminal special characters from observe output #37401
base: main
Are you sure you want to change the base?
Conversation
03c1938
to
511ad4f
Compare
hubble/pkg/printer/terminal.go
Outdated
err error | ||
} | ||
|
||
func (tew *terminalEscaperWriter) Write(a ...interface{}) { |
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.
nit: naming a method Write
when it doesn't implement io.Writer
might be confusing. Also it probably doesn't need to be exported since it's not imported outside this package.
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.
Yeah its the names that were there before. I made it public to differentiate the available API, but I also wanted to rename those to Print and Printf since they map to fmt and not writer.
I'll update
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.
Updated to use the print funcs format
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.
We should add a set of test that actually tests this with each output format to ensure it works when combined with the rest of the code. So basically an e2e test of sorts.
I can add unit tests that use Printer directly and write each supported types containing control sequences and colorized fields. |
Escape special characters from `hubble observe` output when not using JSON formatting to protect against possible malicious character injection. Similar to: kubernetes/kubernetes#101695 Similar to: python/cpython#100001 Signed-off-by: Alexandre Barone <abalexandrebarone@gmail.com>
511ad4f
to
e478216
Compare
I updated existing printer tests to add entries for each output type and colored/not colored. |
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.
Thanks @devodev !
/test |
Escape special characters from
hubble observe
output when not using JSON formatting to protect against possible malicious character injection.This approach escapes characters at the very end, before writing the output to its writer. It also takes care of allowing control characters used to colorize the output. I tried something smart, but we might want to simply escape manually all callsites that may return unsanitized strings before colorizing.
Similar to: kubernetes/kubernetes#101695
Similar to: python/cpython#100001