Skip to content

Commit e76c686

Browse files
fix(telemetry): keep mysql's -P port and redact the real -p password (fixes #815) (#819)
* fix(telemetry): keep mysql's -P port and redact the real -p password The mysql credential rule's i flag let the attached port form -P3306 match as if it were -p, so the port was redacted as a secret and a real password later in the same command survived into OTLP export. Make the rule case-sensitive like the sshpass rule (mysql is the same shape: -p is the password, -P is the port). Fixes #815 Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> * test(telemetry): pin mysql -P port vs -p password scrubbing Mixed -P3306/-phunter2 command keeps the port and redacts the password; lowercase attached form and mysqldump pinned alongside. Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> --------- Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com> Co-authored-by: David McKay <davidmckayv@users.noreply.github.com>
1 parent 8301163 commit e76c686

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎server/src/telemetry/scrub.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const RULES: [RegExp, (match: string, ...groups: string[]) => string][] = [
5757
// `-psecret` for mysql and friends. Nothing separates them: a space means the password is asked for
5858
// at the prompt and the word after `-p` is the database, so only the attached form is redacted.
5959
[
60-
/(\bmysql(?:dump)?\b(?:[^|;&\\\r\n]|\\[\s\S])*?(?:[ \t]|\\\r?\n)-p)("[^"]*"|'[^']*'|[^\s'"-]\S*)/gi,
60+
/(\bmysql(?:dump)?\b(?:[^|;&\\\r\n]|\\[\s\S])*?(?:[ \t]|\\\r?\n)-p)("[^"]*"|'[^']*'|[^\s'"-]\S*)/g,
6161
(_m, lead) => `${lead}${REDACTED}`,
6262
],
6363
// `docker login -p secret`, where `-p` is the password rather than a port.

‎server/tests/enterprise-controls.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ describe("scrubbing commands", () => {
359359
"psql postgres://app:[REDACTED]@db:5432/app",
360360
],
361361
["mysql -uroot -phunter2 app", "mysql -uroot -p[REDACTED] app"],
362+
// `-P` is mysql's port, not its password: the attached port must survive and the real
363+
// password later in the same command must still be redacted (gh-815).
364+
["mysql -h db -P3306 -phunter2 app", "mysql -h db -P3306 -p[REDACTED] app"],
365+
["mysql -uroot -p3306 app", "mysql -uroot -p[REDACTED] app"],
366+
["mysqldump -phunter2 db", "mysqldump -p[REDACTED] db"],
362367
[
363368
"tool --password hunter2 --verbose",
364369
"tool --password [REDACTED] --verbose",

0 commit comments

Comments
 (0)