source-controller/internal
Florian Forster 8be37ef1d2
Fix incorrect use of format strings with the `conditions` package.
Many of the functions in the `conditions` package accept a format string and
(optional) arguments, just like `fmt.Printf` and friends.

In many places, the code passed an error message as the format string, causing
it to be interpreted by the `fmt` package. This leads to issues when the
message contains percent signs, e.g. URL-encoded values.

Consider the following code:

```go
// internal/controller/ocirepository_controller.go
revision, err := r.getRevision(ref, opts)
if err != nil {
	e := serror.NewGeneric(
		fmt.Errorf("failed to determine artifact digest: %w", err),
		ociv1.OCIPullFailedReason,
	)
	conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
	return sreconcile.ResultEmpty, e
}
```

Since `getRevision()` includes the URL in the error message and the error
message is used as a format string, the resulting condition reads:

```
failed to determine artifact digest: GET https://gitlab.com/jwt/auth?scope=repository%!A(MISSING)fforster%!F(MISSING)<REDACTED>%!F(MISSING)k8s-resource-manifests%!A(MISSING)pull&service=container_registry: DENIED: access forbidden
```

This adds an explicit format string and shortens `e.Error()` and
`e.Err.Error()` to `e`, which yields the same output.

To the best of my knowledge, Go is safe from format string attacks. I **don't**
think this is a security vulnerability, but I'm also not a security expert.

Signed-off-by: Florian Forster <fforster@gitlab.com>
2024-07-05 15:55:31 +02:00
..
cache Delete stale metrics on object delete 2023-08-15 02:35:35 +05:30
controller Fix incorrect use of format strings with the `conditions` package. 2024-07-05 15:55:31 +02:00
digest digest: register SHA1 digest algorithm 2023-02-14 12:48:36 +01:00
error Sanitize URLs for bucket fetch error messages. 2024-04-04 15:22:21 +03:00
features gitrepo: remove `OptimizedGitClones` as a feature gate 2023-06-21 16:48:18 +05:30
fs test: use `T.TempDir` to create temporary test directory 2022-04-29 23:01:39 +08:00
helm Use the transport pool 2024-06-14 08:50:33 +02:00
index controllers: use digest for Bucket revision 2023-02-14 12:48:36 +01:00
mock misc: use `Err` prefix for errors 2023-10-09 14:59:58 +02:00
object Promote GitRepository API to v1 2023-03-23 23:17:23 +02:00
oci removing verifyImageSignatures method 2024-03-26 21:53:32 +01:00
predicates Promote Helm APIs to v1 (GA) 2024-05-02 16:04:27 +03:00
reconcile Fix incorrect use of format strings with the `conditions` package. 2024-07-05 15:55:31 +02:00
tls helmrepo: fix Secret type check for TLS via `.spec.secretRef` 2023-09-06 00:27:45 +05:30
transport internal/helm/getter: remove transport reuse test 2022-06-14 09:25:52 +01:00
util Refactor internal OCI package 2022-09-20 18:34:02 +03:00