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

warn users again wrapping fmt.Sprintf() #185

Open
tlimoncelli opened this issue Feb 28, 2023 · 0 comments
Open

warn users again wrapping fmt.Sprintf() #185

tlimoncelli opened this issue Feb 28, 2023 · 0 comments

Comments

@tlimoncelli
Copy link

I recently saw this being submitted in a PR:

return color.RedString(fmt.Sprintf("- DELETE %s", a))

That works, but this is better:

return color.RedString("- DELETE %s", a)

If someone could force user-input so that a := "%v" then color.RedString() would try to interpret the string as a format string, which would be an error. I suspect this could be leveraged to be a security issue.

The README.md should be clear that color.FOOString(fmt.Sprintf(a, b)) is an anti-pattern, and that only color.FOOString(a,b) is needed.

IMHO any function that accepts a format string should have a name that ends with f, such as color.RedStringf(). I realize this is a breaking change, and I hope you consider this change in v2.

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

1 participant