Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions console/src/lib/validate-redirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function validateRedirect(url: string | null | undefined): string {
if (!url) return "/"

const candidate = url
if (!candidate || candidate.startsWith("//") || candidate.startsWith("\\\\")) {
return "/"
}

try {
const parsed = new URL(candidate, window.location.origin)

if (parsed.origin !== window.location.origin) {
return "/"
}

return `${parsed.pathname}${parsed.search}${parsed.hash}`
} catch {
return "/"
}
}
5 changes: 3 additions & 2 deletions console/src/views/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import api from "../../api"
import { type AuthDriver, AUTH_DRIVERS } from "../../types"
import { validateRedirect } from "@/lib/validate-redirect"

import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
Expand Down Expand Up @@ -35,7 +36,7 @@
const [selectedDriver, setSelectedDriver] = useState<AuthDriver>()
const [error, setError] = useState<string>()
const [isSubmitting, setIsSubmitting] = useState(false)
const redirect = searchParams.get("r") ?? "/"
const redirect = validateRedirect(searchParams.get("r"))

const form = useForm<LoginFormValues>({
defaultValues: {
Expand Down Expand Up @@ -227,4 +228,4 @@
</Card>
</div>
)
}
}

Check warning on line 231 in console/src/views/auth/Login.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
3 changes: 2 additions & 1 deletion console/src/views/auth/LoginCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from "react"
import { useClerk } from "@clerk/clerk-react"
import api from "../../api"
import { AUTH_DRIVERS } from "../../types"
import { validateRedirect } from "@/lib/validate-redirect"
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"
import { useTranslation } from "react-i18next"

Expand All @@ -14,7 +15,7 @@ export default function LoginCallback() {
const { driver } = useParams() as { driver: string }
const [searchParams] = useSearchParams()
const [error, setError] = useState<string>()
const redirect = searchParams.get("r") ?? "/"
const redirect = validateRedirect(searchParams.get("r"))

useEffect(() => {
const handleAuth = async () => {
Expand Down
13 changes: 7 additions & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ func (n Node) PublicBaseURL() string {
}

type Auth struct {
Driver string `env:"DRIVER"`
JWTSecret string `env:"JWT_SECRET"`
JWKS claim.JWKS `env:"JWKS_URL"`
TokenLife time.Duration `env:"TOKEN_LIFE" envDefault:"24h"`
Basic BasicAuth `envPrefix:"BASIC_"`
Clerk ClerkAuth `envPrefix:"CLERK_"`
Driver string `env:"DRIVER"`
JWTSecret string `env:"JWT_SECRET"`
JWKS claim.JWKS `env:"JWKS_URL"`
TokenLife time.Duration `env:"TOKEN_LIFE" envDefault:"24h"`
AllowedRedirectHosts []string `env:"ALLOWED_REDIRECT_HOSTS"`
Basic BasicAuth `envPrefix:"BASIC_"`
Clerk ClerkAuth `envPrefix:"CLERK_"`
}

type BasicAuth struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/http/controllers/v1/management/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ func (c *AuthController) writeAuthError(w http.ResponseWriter, err error) {
default:
oapi.WriteProblem(w, problem.ErrInternal(problem.Describe("authentication failed")))
}
}
}
2 changes: 1 addition & 1 deletion internal/http/controllers/v1/management/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ func TestAuthWebhookWithInvalidDriver(t *testing.T) {
require.Equal(t, test.code, res.Code, res.Body.String())
})
}
}
}
4 changes: 0 additions & 4 deletions internal/http/controllers/v1/management/oapi/resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8417,10 +8417,6 @@ components:
type: string
description: Password (required for basic auth)
example: "password123"
redirect:
type: string
description: URL to redirect after successful auth
example: "/"

EmailTemplate:
type: object
Expand Down
Loading