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.
28 lines
1.5 KiB
Go
28 lines
1.5 KiB
Go
package identity
|
|
|
|
import "testing"
|
|
|
|
func TestAuthenticationSettingsRejectUntrustedOrigins(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, url, issuer, client, audience string
|
|
want bool
|
|
}{
|
|
{name: "public TLS", url: "https://archie.example", want: true},
|
|
{name: "localhost", url: "http://localhost:8484", want: true},
|
|
{name: "userinfo is not an origin", url: "https://user:password@archie.example", want: false}, //nolint:gosec // G101: a fake URL with userinfo, which must be refused.
|
|
{name: "URL path cannot change the RP origin", url: "https://archie.example/subpath", want: false},
|
|
{name: "query is not an origin", url: "https://archie.example?token=1", want: false},
|
|
{name: "complete provider", url: "https://archie.example", issuer: "https://identity.example", client: "archie", audience: "archie", want: true},
|
|
{name: "remote insecure provider", url: "https://archie.example", issuer: "http://identity.example", client: "archie", audience: "archie", want: false},
|
|
{name: "issuer without client", url: "https://archie.example", issuer: "https://identity.example", audience: "archie", want: false},
|
|
{name: "audience without provider", url: "https://archie.example", audience: "archie", want: false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := (AuthenticationSettings{PublicURL: tc.url, OIDCIssuer: tc.issuer, OIDCClientID: tc.client, OIDCAudience: tc.audience}).Validate()
|
|
if (err == nil) != tc.want {
|
|
t.Fatalf("validation err=%v, allowed=%v", err, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|