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:
sam committed 2026-11-13 03:16:15 +11:00
1 parent a3d4b751b9
commit db346b159d
46 files changed
+199 -115

No files matched your search

@@ -89,7 +89,7 @@ func bundledMigrationURL() string {
// database as an explicit choice, switching to it must generate PGPASSWORD
// into the sink, and keeping must leave the existing URL untouched.
func TestRunParamsDatabaseChoice(t *testing.T) {
const existing = "postgres://operator:secret@db.internal:5432/archie"
const existing = "postgres://operator:secret@db.internal:5432/archie" //nolint:gosec // G101: a fake database URL.
tests := []struct {
name string
@@ -18,6 +18,7 @@ type cloudProvider struct {
apiKeyEnv string
}
//nolint:gosec // G101: env var names, not values.
var cloudProviders = []cloudProvider{
{name: "OpenAI", class: "openai", apiKeyEnv: "OPENAI_API_KEY"},
{name: "Anthropic", class: "anthropic", apiKeyEnv: "ANTHROPIC_API_KEY"},
@@ -4,7 +4,7 @@ import "github.com/samcharles93/archie-core/internal/config"
// CredentialBindingsKind is the resource mapping credential service names to
// org secrets. Applied live on each launch.
const CredentialBindingsKind = "credential-bindings"
const CredentialBindingsKind = "credential-bindings" //nolint:gosec // G101: a resource kind, not a credential.
// credentialBinding is one config.CredentialBinding as the document writes
// it: explicit snake_case json tags, following channel_settings.go /
+1 -1
View File
@@ -97,7 +97,7 @@ func createCA(dir, certPath, keyPath string) (*CA, error) {
if err := os.WriteFile(keyPath, keyPEM, 0o600); err != nil {
return nil, err
}
if err := os.WriteFile(certPath, certPEM, 0o644); err != nil {
if err := os.WriteFile(certPath, certPEM, 0o644); err != nil { //nolint:gosec // G306: a CA certificate is public; its key is written 0600 above.
return nil, err
}
return parseCA(certPEM, keyPEM)
@@ -100,7 +100,7 @@ func TestUsableProviderCredentials(t *testing.T) {
// again.
func TestMergeProvidersKeepsDisabled(t *testing.T) {
merged := mergeProviders(
map[string]config.Provider{"openai": {Class: "openai", APIKeyEnv: "OPENAI_API_KEY"}},
map[string]config.Provider{"openai": {Class: "openai", APIKeyEnv: "OPENAI_API_KEY"}}, //nolint:gosec // G101: an env var name, not a value.
map[string]config.Provider{"openai": {Disabled: true}},
)
if !merged["openai"].Disabled {
@@ -21,9 +21,9 @@ func testProvisionRoles() provisionRoles {
// plan that would leave the runtime role owning schema changes.
func TestParseProvisionURLs(t *testing.T) {
const (
adminURL = "postgres://archie:admin@db.internal/archie"
runtimeURL = "postgres://archie_runtime:runtime@db.internal/archie"
migrationURL = "postgres://archie_migrator:migration@db.internal/archie"
adminURL = "postgres://archie:admin@db.internal/archie" //nolint:gosec // G101: fake database URLs.
runtimeURL = "postgres://archie_runtime:runtime@db.internal/archie" //nolint:gosec // G101: fake database URLs.
migrationURL = "postgres://archie_migrator:migration@db.internal/archie" //nolint:gosec // G101: fake database URLs.
)
tests := []struct {
name string
@@ -75,7 +75,7 @@ func TestParseProvisionURLs(t *testing.T) {
},
{
name: "the same role cannot be runtime and migration",
opts: ProvisionOptions{AdminURL: adminURL, RuntimeURL: runtimeURL, MigrationURL: "postgres://archie_runtime:other@db.internal/archie"},
opts: ProvisionOptions{AdminURL: adminURL, RuntimeURL: runtimeURL, MigrationURL: "postgres://archie_runtime:other@db.internal/archie"}, //nolint:gosec // G101: a fake database URL.
wantErr: "same role",
},
{
@@ -85,7 +85,7 @@ func TestParseProvisionURLs(t *testing.T) {
},
{
name: "a non-PostgreSQL URL is refused",
opts: ProvisionOptions{AdminURL: "mysql://archie:admin@db.internal/archie", RuntimeURL: runtimeURL, MigrationURL: migrationURL},
opts: ProvisionOptions{AdminURL: "mysql://archie:admin@db.internal/archie", RuntimeURL: runtimeURL, MigrationURL: migrationURL}, //nolint:gosec // G101: a fake database URL.
wantErr: "postgres:// URL",
},
{
+1 -1
View File
@@ -130,7 +130,7 @@ func writeEntry(destDir, prefix string, e tarEntry) error {
if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil {
return err
}
return os.WriteFile(target, e.data, 0o644)
return os.WriteFile(target, e.data, 0o644) //nolint:gosec // G306: the task container reads the checkout as another user.
default:
// Symlinks, devices, etc: not followed, not written.
return nil
@@ -14,7 +14,7 @@ import (
// at all and there is nothing here to test.
func requireNamespaces(t *testing.T) {
t.Helper()
cmd := exec.CommandContext(t.Context(), os.Args[0], "-test.run=^$")
cmd := exec.CommandContext(t.Context(), os.Args[0], "-test.run=^$") //nolint:gosec // G702: re-runs this test binary.
cmd.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: syscall.CLONE_NEWUSER | syscall.CLONE_NEWNET,
UidMappings: []syscall.SysProcIDMap{{ContainerID: os.Getuid(), HostID: os.Getuid(), Size: 1}},
@@ -103,7 +103,7 @@ func TestMain(m *testing.M) {
func selfDigest(t *testing.T) string {
t.Helper()
binary, err := os.ReadFile(os.Args[0])
binary, err := os.ReadFile(os.Args[0]) //nolint:gosec // G703: reads this test binary.
if err != nil {
t.Fatal(err)
}
@@ -243,7 +243,7 @@ func layerOf(t *testing.T, name string, content []byte) []byte {
// An extension runs only while its package is accepted and the settings enable
// it, and stops the moment either stops being true.
func TestRunnerRunsOnlyWhatIsAcceptedAndEnabled(t *testing.T) {
binary, err := os.ReadFile(os.Args[0])
binary, err := os.ReadFile(os.Args[0]) //nolint:gosec // G703: reads this test binary.
if err != nil {
t.Fatal(err)
}
@@ -85,7 +85,7 @@ func (s *Store) Write(_ context.Context, sk curator.Skill) error {
if info, err := os.Stat(dir); err != nil || !info.IsDir() {
return fmt.Errorf("skillcurator: skill %q does not exist under %s", sk.Name, s.skillsPath())
}
if err := os.WriteFile(s.skillPath(sk.Name), []byte(sk.Content), 0o644); err != nil {
if err := os.WriteFile(s.skillPath(sk.Name), []byte(sk.Content), 0o644); err != nil { //nolint:gosec // G306: agents read skills as another user.
return fmt.Errorf("skillcurator: writing %s: %w", s.skillPath(sk.Name), err)
}
return nil
@@ -14,7 +14,7 @@ func TestModelProviderWireCarriesCredentialRef(t *testing.T) {
t.Parallel()
sent := map[string]config.Provider{
"remote": {
"remote": { //nolint:gosec // G101: env var and secret names, not values.
Class: "deepseek",
BaseURL: "https://example.invalid/v1",
APIKeyEnv: "REMOTE_API_KEY",
+1 -1
View File
@@ -153,7 +153,7 @@ func validateLayer(layer []byte, mediaType string, files []domain.File) error {
return err
}
found[header.Name] = true
if _, err := io.Copy(io.Discard, tarReader); err != nil {
if _, err := io.Copy(io.Discard, tarReader); err != nil { //nolint:gosec // G110: the tar reader is bounded by io.LimitReader(maxPackageBytes).
return err
}
}