Skip to content

Commit

Permalink
fix(steam): improve open id validation (#184)
Browse files Browse the repository at this point in the history
* fix(steam): open id validation

* chore: lint

* chore: check steam id

* [autofix.ci] apply automated fixes

* chore: update error message

* chore: adjust steam id checker

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
ahmedrangel and autofix-ci[bot] authored Sep 23, 2024
1 parent c6dd890 commit 6ae7317
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/runtime/server/lib/oauth/steam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,31 @@ export function oauthSteamEventHandler({ config, onSuccess, onError }: OAuthConf
return sendRedirect(event, withQuery(config.authorizationURL as string, steamOpenIdParams))
}

// Validate OpenID Authentication
const validateAuth: string = await $fetch(withQuery(config.authorizationURL as string, {
...query,
'openid.mode': 'check_authentication',
}))
const openIdCheck = {
ns: 'http://specs.openid.net/auth/2.0',
claimed_id: 'https://steamcommunity.com/openid/id/',
identity: 'https://steamcommunity.com/openid/id/',
}

const idRegex = /^https?:\/\/steamcommunity\.com\/openid\/id\/(\d+)$/
const steamIdCheck = idRegex.exec(query['openid.claimed_id'])

if (!validateAuth.includes('is_valid:true')) {
if (
query['openid.op_endpoint'] !== config.authorizationURL
|| !steamIdCheck
|| query['openid.ns'] !== openIdCheck.ns
|| !query['openid.claimed_id']?.startsWith(openIdCheck.claimed_id)
|| !query['openid.identity']?.startsWith(openIdCheck.identity)
) {
const error = createError({
statusCode: 401,
message: 'Steam login failed: Unknown error',
message: 'Steam login failed: Claimed identity is invalid.',
})
if (!onError) throw error
return onError(event, error)
}

const steamId = query['openid.claimed_id'].split('/').pop()
const steamId = steamIdCheck[1]

// TODO: improve typing
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 6ae7317

Please sign in to comment.