2016-12-25 14:31:52 -05:00
|
|
|
package credentials
|
|
|
|
|
|
|
|
import (
|
Use golang.org/x/sys/execabs
On Windows, the os/exec.{Command,CommandContext,LookPath} functions
resolve command names that have neither path separators nor file extension
(e.g., "git") by first looking in the current working directory before
looking in the PATH environment variable.
Go maintainers intended to match cmd.exe's historical behavior.
However, this is pretty much never the intended behavior and as an abundance of precaution
this patch prevents that when executing commands.
Example of commands that docker.exe may execute: `git`, `docker-buildx` (or other cli plugin), `docker-credential-wincred`, `docker`.
Note that this was prompted by the [Go 1.15.7 security fixes](https://blog.golang.org/path-security), but unlike in `go.exe`,
the windows path lookups in docker are not in a code path allowing remote code execution, thus there is no security impact on docker.
Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 8d199d5bba9db46b6610bd959d815ce7197402b3)
Signed-off-by: Tibor Vass <tibor@docker.com>
2021-01-25 14:18:54 -05:00
|
|
|
exec "golang.org/x/sys/execabs"
|
2016-12-25 14:31:52 -05:00
|
|
|
)
|
|
|
|
|
2017-06-21 16:47:06 -04:00
|
|
|
// DetectDefaultStore return the default credentials store for the platform if
|
|
|
|
// the store executable is available.
|
|
|
|
func DetectDefaultStore(store string) string {
|
2017-08-14 10:58:19 -04:00
|
|
|
platformDefault := defaultCredentialsStore()
|
|
|
|
|
2017-06-21 16:47:06 -04:00
|
|
|
// user defined or no default for platform
|
2017-08-14 10:58:19 -04:00
|
|
|
if store != "" || platformDefault == "" {
|
2017-06-21 16:47:06 -04:00
|
|
|
return store
|
2016-12-25 14:31:52 -05:00
|
|
|
}
|
|
|
|
|
2017-08-14 10:58:19 -04:00
|
|
|
if _, err := exec.LookPath(remoteCredentialsPrefix + platformDefault); err == nil {
|
|
|
|
return platformDefault
|
2016-12-25 14:31:52 -05:00
|
|
|
}
|
2017-06-21 16:47:06 -04:00
|
|
|
return ""
|
2016-12-25 14:31:52 -05:00
|
|
|
}
|