Skip to content

Startup echo of "Options:" prints the connection string password to stdout #260

Description

@christianbraun

What happens

Main echoes the raw argument vector before anything else:

Console.WriteLine("Tool: pg2b3dm " + version);
Console.WriteLine("Options: " + string.Join(" ", args));

Since --connection is the supported way to pass credentials, any non-interactive run puts the
database password in stdout verbatim:

Options: -t citydb.my_surface --connection Host=db.example.org;Port=5432;Username=tiler;Password=hunter2 -o out

Why it matters

The interactive path is already careful - PasswordAsker prompts and never echoes. But an automated
run (CI job, cron, nohup ... > bake.log) has no interactive path, so it must use --connection, and
that is exactly the case whose output gets captured and kept. The consequence is that ordinary build
logs become secrets: they need the same handling as a credentials file, and anyone who has ever pasted
a pg2b3dm log into an issue has published a password.

We hit this baking 3D Tiles from 3DCityDB v5 in a scripted pipeline. Our wrapper masks the string in
its own logging, but it cannot stop pg2b3dm writing it to stdout - the only workaround left is
filtering the tool's output, or deleting the logs afterwards, which is what we ended up doing.

Suggested fix

Redact the password before the echo rather than dropping the line - the Options: echo is genuinely
useful for reproducing a run. Something like:

Console.WriteLine("Options: " + string.Join(" ", args.Select(Redact)));

// Password=... (and the Npgsql alias pwd=...) inside a connection string argument
private static string Redact(string arg)
    => Regex.Replace(arg, @"(?<=\b(password|pwd)\s*=)[^;]*", "***", RegexOptions.IgnoreCase);

That keeps host, database, user and every other option visible, which is what makes the line worth
printing.

Happy to open a PR with the redaction plus a unit test on the helper if you would take it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions