Skip to content
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

pizza-logger Sanitization Bug #103

Open
frozenfrank opened this issue Nov 29, 2024 · 1 comment
Open

pizza-logger Sanitization Bug #103

frozenfrank opened this issue Nov 29, 2024 · 1 comment

Comments

@frozenfrank
Copy link
Contributor

(Because I couldn't find the actual pizza-logger repository, this was the next best place I could find to report the issue.)

Overview

During sanitization, the replacement REGEX incorrectly replaces an equals sign = with a colon character :.

This will not affect the runtime behavior of any dependent applications, but it could affect the way the logs are viewed. The wrong JS syntax could cause the JSON parser to mess up or display unexpected results in a dashboard context.

Source Code Snippet

// pizza-logger/index.js:55
  sanitize(logData) {
    logData = JSON.stringify(logData);
    logData = logData.replace(/\\"password\\":\s*\\"[^"]*\\"/g, '\\"password\\": \\"*****\\"');
    logData = logData.replace(/\\password\\=\s*\\"[^"]*\\"/g, '\\"password\\": \\"*****\\"');   // Bug on this line replace = with :
    return logData;
  }

Proposed solution No. 1 (simple)

Simply replace the colon : with an equals sign = to preserve the JS syntax.

// pizza-logger/index.js:55
  sanitize(logData) {
    logData = JSON.stringify(logData);
    logData = logData.replace(/\\"password\\":\s*\\"[^"]*\\"/g, '\\"password\\": \\"*****\\"');
    logData = logData.replace(/\\password\\=\s*\\"[^"]*\\"/g, '\\password\\= \\"*****\\"');   // Bug on this line replace = with :
    return logData;
  }

Proposed solution No. 2 (preferred)

Generalize the REGEX to do both replacements in one line. Use capturing groups to preserve important variations like (:/=).

I cannot propose a solution here because I'm personally confused by the differences in the double quotes and backslashes. The more I look at the code samples, I think the second line is simply unnecessary (I don't think the backslashed double-quote characters are actually behaving as intended).

@leesjensen
Copy link
Contributor

@isawamoose - do you want to correct this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants