Skip to content

Commit 0b342cb

Browse files
Merge pull request #469 from codeanker/development
2.12.0
2 parents ea374d5 + 3a75793 commit 0b342cb

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

apps/api/src/routes/oidc/index.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ oidcRouter.get('/dlrg/callback', async (c) => {
6868
Authorization: `Bearer ${result.access_token}`,
6969
},
7070
})
71-
const profileRaw = await userInfoResponse.json() as Record<string, unknown>
71+
const profileRaw = (await userInfoResponse.json()) as Record<string, unknown>
7272
const profile = ZProfile.parse(profileRaw)
7373
const existingUser = await prisma.account.findUnique({
7474
where: {
@@ -136,16 +136,41 @@ oidcRouter.get('/dlrg/login', async (c) => {
136136
const as = await oauth.processDiscoveryResponse(issuer, discoveryRequestResponse)
137137
const authorizationUrl = new URL(as.authorization_endpoint!)
138138

139+
const requestHost = c.req.header('Host')?.trim().toLowerCase()
140+
if (!requestHost) {
141+
return c.text('Invalid domain', 400)
142+
}
143+
144+
// Accept hostnames stored as plain host, with port, or as full URL.
145+
const hostFromHeader = new URL(`http://${requestHost}`)
146+
const candidateHostnames = Array.from(
147+
new Set([
148+
requestHost,
149+
hostFromHeader.host,
150+
hostFromHeader.hostname,
151+
`https://${hostFromHeader.host}`,
152+
`https://${hostFromHeader.hostname}`,
153+
`http://${hostFromHeader.host}`,
154+
`http://${hostFromHeader.hostname}`,
155+
])
156+
)
157+
139158
const host = await prisma.hostname.findFirst({
140159
where: {
141-
hostname: c.req.header('Host'),
142-
}
160+
hostname: {
161+
in: candidateHostnames,
162+
},
163+
},
143164
})
144165
if (host === null) {
145166
return c.text('Invalid domain', 400)
146167
}
147168

148-
const redirectUri = new URL('/api/connect/dlrg/callback', host.hostname)
169+
const redirectBase =
170+
host.hostname.startsWith('http://') || host.hostname.startsWith('https://')
171+
? host.hostname
172+
: `https://${host.hostname}`
173+
const redirectUri = new URL('/api/connect/dlrg/callback', redirectBase)
149174
const registerAs = c.req.query('as')?.trim()
150175
if (registerAs !== undefined && registerAs?.length > 0) {
151176
redirectUri.searchParams.set('as', registerAs)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "codeanker-project",
33
"author": "CODEANKER GmbH",
4-
"version": "2.11.0",
4+
"version": "2.12.0",
55
"description": "",
66
"license": "CC-BY-3.0-DE",
77
"workspaces": [

0 commit comments

Comments
 (0)