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

sprintf-args check false positive when format is a string variable #1104

Closed
srenatus opened this issue Sep 12, 2024 · 1 comment · Fixed by #1107
Closed

sprintf-args check false positive when format is a string variable #1104

srenatus opened this issue Sep 12, 2024 · 1 comment · Fixed by #1107

Comments

@srenatus
Copy link
Member

package play

import rego.v1

bye if {
	query_fmt := "SELECT name FROM roles INNER JOIN users ON roles.user_id = users.id WHERE users.name = %s"
	_ = sprintf(query_fmt, ["me"])
}

This shouldn't be flagged, but it is. Playground

@anderseknert
Copy link
Member

Thanks! Hmm, yeah, that should be easy to account for, I think. I'll take a look.

anderseknert added a commit that referenced this issue Sep 12, 2024
While I started looking into #1104 I encountered some cases where
`ast.ref_to_string`, and it's `static` counterpart would return wrong
representations. We already had a bit of a homegrown format, which was
convenient for some things, but would also leak out in places where
it shouldn't be. Now use the same format as OPA for representing refs
as strings.

Also added the query in error messages where we fail to prepare or
eval in a couple of places, as the lack of those made debugging this
issue much harder than it had to be.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 12, 2024
While I started looking into #1104 I encountered some cases where
`ast.ref_to_string`, and it's `static` counterpart would return wrong
representations. We already had a bit of a homegrown format, which was
convenient for some things, but would also leak out in places where
it shouldn't be. Now use the same format as OPA for representing refs
as strings.

Also added the query in error messages where we fail to prepare or
eval in a couple of places, as the lack of those made debugging this
issue much harder than it had to be.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 12, 2024
While I started looking into #1104 I encountered some cases where
`ast.ref_to_string`, and it's `static` counterpart would return wrong
representations. We already had a bit of a homegrown format, which was
convenient for some things, but would also leak out in places where
it shouldn't be. Now use the same format as OPA for representing refs
as strings.

Also added the query in error messages where we fail to prepare or
eval in a couple of places, as the lack of those made debugging this
issue much harder than it had to be.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Sep 12, 2024
While this rule likely never will catch all violations, as some are just
too expensive to find for something very unlikely — it should never report
false positives.

Fixes #1104

Signed-off-by: Anders Eknert <anders@styra.com>
srenatus pushed a commit to srenatus/regal that referenced this issue Oct 1, 2024
While I started looking into StyraInc#1104 I encountered some cases where
`ast.ref_to_string`, and it's `static` counterpart would return wrong
representations. We already had a bit of a homegrown format, which was
convenient for some things, but would also leak out in places where
it shouldn't be. Now use the same format as OPA for representing refs
as strings.

Also added the query in error messages where we fail to prepare or
eval in a couple of places, as the lack of those made debugging this
issue much harder than it had to be.

Signed-off-by: Anders Eknert <anders@styra.com>
srenatus pushed a commit to srenatus/regal that referenced this issue Oct 1, 2024
…at (StyraInc#1107)

While this rule likely never will catch all violations, as some are just
too expensive to find for something very unlikely — it should never report
false positives.

Fixes StyraInc#1104

Signed-off-by: Anders Eknert <anders@styra.com>
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.

2 participants