Skip to content
Merged
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
33 changes: 29 additions & 4 deletions apps/api/src/routes/oidc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ oidcRouter.get('/dlrg/callback', async (c) => {
Authorization: `Bearer ${result.access_token}`,
},
})
const profileRaw = await userInfoResponse.json() as Record<string, unknown>
const profileRaw = (await userInfoResponse.json()) as Record<string, unknown>
const profile = ZProfile.parse(profileRaw)
const existingUser = await prisma.account.findUnique({
where: {
Expand Down Expand Up @@ -136,16 +136,41 @@ oidcRouter.get('/dlrg/login', async (c) => {
const as = await oauth.processDiscoveryResponse(issuer, discoveryRequestResponse)
const authorizationUrl = new URL(as.authorization_endpoint!)

const requestHost = c.req.header('Host')?.trim().toLowerCase()
if (!requestHost) {
return c.text('Invalid domain', 400)
}

// Accept hostnames stored as plain host, with port, or as full URL.
const hostFromHeader = new URL(`http://${requestHost}`)
const candidateHostnames = Array.from(
new Set([
requestHost,
hostFromHeader.host,
hostFromHeader.hostname,
`https://${hostFromHeader.host}`,
`https://${hostFromHeader.hostname}`,
`http://${hostFromHeader.host}`,
`http://${hostFromHeader.hostname}`,
])
)

const host = await prisma.hostname.findFirst({
where: {
hostname: c.req.header('Host'),
}
hostname: {
in: candidateHostnames,
},
},
})
if (host === null) {
return c.text('Invalid domain', 400)
}

const redirectUri = new URL('/api/connect/dlrg/callback', host.hostname)
const redirectBase =
host.hostname.startsWith('http://') || host.hostname.startsWith('https://')
? host.hostname
: `https://${host.hostname}`
const redirectUri = new URL('/api/connect/dlrg/callback', redirectBase)
const registerAs = c.req.query('as')?.trim()
if (registerAs !== undefined && registerAs?.length > 0) {
redirectUri.searchParams.set('as', registerAs)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "codeanker-project",
"author": "CODEANKER GmbH",
"version": "2.11.0",
"version": "2.12.0",
"description": "",
"license": "CC-BY-3.0-DE",
"workspaces": [
Expand Down
Loading