fix(webui): mark cookies Secure behind a TLS proxy; run gosec in the gate (#1919)
Cookies took Secure from r.TLS, which is nil behind a proxy that terminates TLS, so sign-in cookies went out without it. Every dashboard cookie now goes through one builder that reads the scheme the way the origin check does. The worktree reset and the agent worker's chown walk use os.Root, so a symlink swapped in mid-walk can't point them outside the worktree. gosec runs in golangci-lint, tests included. G104, G115, G204 and G304 are excluded in config; each remaining finding is fixed or suppressed at the site with its reason.
This commit is contained in:
46 files changed
+199
-115
No files matched your search
@@ -111,13 +111,19 @@ func (h *hybridTrees) HasUncommittedChanges(ctx context.Context, dir string) (bo
|
||||
|
||||
var _ workflow.Trees = (*hybridTrees)(nil)
|
||||
|
||||
// chownTree recursively lchowns dir to uid:gid.
|
||||
// chownTree recursively lchowns dir to uid:gid, through a root so a symlink
|
||||
// swapped in mid-walk cannot point it outside dir.
|
||||
func chownTree(dir string, uid, gid int) error {
|
||||
return filepath.WalkDir(dir, func(path string, _ fs.DirEntry, err error) error {
|
||||
root, err := os.OpenRoot(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = root.Close() }()
|
||||
return fs.WalkDir(root.FS(), ".", func(path string, _ fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Lchown(path, uid, gid)
|
||||
return root.Lchown(path, uid, gid)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -43,13 +43,13 @@ func TestModelEgressResolvesProviderSecretRefs(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "an env-only provider keeps its binding",
|
||||
provider: config.Provider{Class: "openai", APIKeyEnv: "PROVIDER_ENV_KEY"},
|
||||
provider: config.Provider{Class: "openai", APIKeyEnv: "PROVIDER_ENV_KEY"}, //nolint:gosec // G101: env var and secret names, not values.
|
||||
bindings: []config.CredentialBinding{{Service: "used", Org: "org-test", Secret: config.SecretRef{Engine: "env", Key: "PROVIDER_KEY"}}},
|
||||
wantEnv: "PROVIDER_ENV_KEY",
|
||||
},
|
||||
{
|
||||
name: "an env-only provider without a binding is refused",
|
||||
provider: config.Provider{Class: "openai", APIKeyEnv: "PROVIDER_ENV_KEY"},
|
||||
provider: config.Provider{Class: "openai", APIKeyEnv: "PROVIDER_ENV_KEY"}, //nolint:gosec // G101: env var and secret names, not values.
|
||||
wantErr: "no credential binding",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/cgi"
|
||||
"net/http/cgi" //nolint:gosec // G504: serves git http-backend; the Httpoxy CVE predates Go 1.6.3.
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
@@ -16,8 +16,10 @@ func TestUpdateTopologyRefusal(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
config := filepath.Join(root, "config.toml")
|
||||
required := releaseupdate.Topology{Units: []string{"archie-state-store", "archie-gateway", "archied"}, ConfigSections: []string{"services.state", "services.gateway"}}
|
||||
writeUpdateFixture(t, config, "[services.state]\ntarget='localhost:9090'\n")
|
||||
writeUpdateFixture(t, filepath.Join(root, "systemctl"), "#!/bin/sh\nprintf 'archied.service enabled enabled\\n'\n")
|
||||
if err := os.WriteFile(config, []byte("[services.state]\ntarget='localhost:9090'\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeScript(t, filepath.Join(root, "systemctl"), "#!/bin/sh\nprintf 'archied.service enabled enabled\\n'\n")
|
||||
t.Setenv("PATH", root+":"+os.Getenv("PATH"))
|
||||
var output bytes.Buffer
|
||||
if err := checkUpdateTopology(t.Context(), config, required, true, &output); err == nil {
|
||||
@@ -39,8 +41,8 @@ func TestResumeUpdate(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
called := filepath.Join(root, "called")
|
||||
writeUpdateFixture(t, filepath.Join(root, "systemd-run"), "#!/bin/sh\nprintf '%s\\n' \"$@\" > '"+called+"'\n")
|
||||
writeUpdateFixture(t, filepath.Join(root, "systemctl"), "#!/bin/sh\n")
|
||||
writeScript(t, filepath.Join(root, "systemd-run"), "#!/bin/sh\nprintf '%s\\n' \"$@\" > '"+called+"'\n")
|
||||
writeScript(t, filepath.Join(root, "systemctl"), "#!/bin/sh\n")
|
||||
t.Setenv("PATH", root+":"+os.Getenv("PATH"))
|
||||
lock, err := os.OpenFile(filepath.Join(root, "lock"), os.O_CREATE|os.O_RDWR, 0o600)
|
||||
if err != nil {
|
||||
@@ -69,9 +71,10 @@ func TestResumeUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func writeUpdateFixture(t *testing.T, path, data string) {
|
||||
// writeScript writes a stand-in for a host command the update runs.
|
||||
func writeScript(t *testing.T, path, data string) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(path, []byte(data), 0o700); err != nil {
|
||||
if err := os.WriteFile(path, []byte(data), 0o700); err != nil { //nolint:gosec // G306: a script needs the execute bit.
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
const telegramCredential = "telegram"
|
||||
|
||||
// credentialBindingsKind is the control-plane resource holding the bindings.
|
||||
const credentialBindingsKind = "credential-bindings"
|
||||
const credentialBindingsKind = "credential-bindings" //nolint:gosec // G101: a credential service name, not a credential.
|
||||
|
||||
// orgChannelSource is where the Messaging Service learns which orgs run a
|
||||
// channel and how they are bound. *controlplanerpc.Client satisfies the first
|
||||
|
||||
@@ -193,5 +193,5 @@ func writeReport(dir, report string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
path := filepath.Join(dir, "pr-review-"+time.Now().UTC().Format("20060102-150405")+".md")
|
||||
return path, os.WriteFile(path, []byte(report), 0o644)
|
||||
return path, os.WriteFile(path, []byte(report), 0o644) //nolint:gosec // G306: a report for the operator to read.
|
||||
}
|
||||
Reference in new issue
Block a user