Skip to content

Passwords should be excluded from toString #16851

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

Closed
mgrafl opened this issue Oct 17, 2023 · 2 comments · Fixed by #16942
Closed

Passwords should be excluded from toString #16851

mgrafl opened this issue Oct 17, 2023 · 2 comments · Fixed by #16942

Comments

@mgrafl
Copy link

mgrafl commented Oct 17, 2023

For the Java Spring generator (and potentially others), the generated toString method includes all properties:

{{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n");

The properties may include sensitive information, such as passwords.
Since the toString method is primarily used for logging purposes, sensitive information should be redacted (see also CWE-532).

The OpenAPI specification already has the modifier property called format, that can be set to password as a hint that a field contains sensitive information (see https://spec.openapis.org/oas/v3.1.0#data-types).

Proposed mitigation:

  • The generator(s) should honor this hint in the generated toString method and skip (or redact) fields that are marked as format: password.

Compatibility considerations:

  • Since the toString method includes the class name before the opening curly brackets, there is no risk that developers might mistakenly use the toString method for JSON serialization.

Related issues:

@mgrafl mgrafl changed the title Passwords should not excluded from toString Passwords should be excluded from toString Oct 17, 2023
@dabdirb
Copy link
Contributor

dabdirb commented Oct 18, 2023

the better solution is not exclude password field from toString() method, replace password as another string, such as "***" or "[MASKED]".
PR #16942

@wing328
Copy link
Member

wing328 commented Nov 5, 2023

closed via #16942

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

Successfully merging a pull request may close this issue.

3 participants