source-controller/internal/controller
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
..
testdata Introduce a semver filter in OCIRepository 2024-03-28 00:09:51 +01:00
artifact.go Move controllers to internal/controller 2023-05-03 15:35:45 +05:30
artifact_matchers_test.go Move controllers to internal/controller 2023-05-03 15:35:45 +05:30
artifact_test.go Move controllers to internal/controller 2023-05-03 15:35:45 +05:30
bucket_controller.go Fix incorrect use of format strings with the `conditions` package. 2024-07-05 15:55:31 +02:00
bucket_controller_fetch_test.go bucket: Add prefix filtering capability 2023-10-17 14:13:04 +03:00
bucket_controller_test.go Add support for .spec.proxySecretRef for generic provider of Bucket API 2024-07-03 15:10:47 +01:00
common_test.go Move controllers to internal/controller 2023-05-03 15:35:45 +05:30
gitrepository_controller.go Fix incorrect use of format strings with the `conditions` package. 2024-07-05 15:55:31 +02:00
gitrepository_controller_fuzz_test.go update dependencies and switch to `go-git/go-git` 2023-05-26 13:46:48 +05:30
gitrepository_controller_test.go Update dependencies to Kubernetes 1.28 2023-11-20 16:50:44 +02:00
helmchart_controller.go Fix incorrect use of format strings with the `conditions` package. 2024-07-05 15:55:31 +02:00
helmchart_controller_test.go docs: Add API spec for Helm v1 2024-05-02 16:19:48 +03:00
helmrepository_controller.go Fix incorrect use of format strings with the `conditions` package. 2024-07-05 15:55:31 +02:00
helmrepository_controller_test.go Promote Helm APIs to v1 (GA) 2024-05-02 16:04:27 +03:00
ocirepository_controller.go Fix incorrect use of format strings with the `conditions` package. 2024-07-05 15:55:31 +02:00
ocirepository_controller_test.go Promote Helm APIs to v1 (GA) 2024-05-02 16:04:27 +03:00
source_predicate.go Move controllers to internal/controller 2023-05-03 15:35:45 +05:30
storage.go storage: change default file permissions 2023-11-06 12:22:40 +01:00
storage_test.go update dependencies and switch to `go-git/go-git` 2023-05-26 13:46:48 +05:30
suite_test.go allow insecure registry login 2024-04-18 13:12:18 +00:00