@@ -38,35 +38,58 @@ export function defineOAuthSteamEventHandler({ config, onSuccess, onError }: OAu
3838 return handleMissingConfiguration ( event , 'steam' , [ 'apiKey' ] , onError )
3939 }
4040
41+ const url = getRequestURL ( event )
42+
4143 if ( ! query [ 'openid.claimed_id' ] ) {
4244 const redirectURL = config . redirectURL || getRequestURL ( event ) . href
4345 const steamOpenIdParams = {
4446 'openid.ns' : 'http://specs.openid.net/auth/2.0' ,
4547 'openid.mode' : 'checkid_setup' ,
4648 'openid.return_to' : redirectURL ,
49+ 'openid.realm' : `${ url . protocol } //${ url . hostname } ` ,
4750 'openid.identity' : 'http://specs.openid.net/auth/2.0/identifier_select' ,
4851 'openid.claimed_id' : 'http://specs.openid.net/auth/2.0/identifier_select' ,
4952 }
5053 // Redirect to Steam Oauth page
5154 return sendRedirect ( event , withQuery ( config . authorizationURL as string , steamOpenIdParams ) )
5255 }
5356
54- const openIdCheck = {
55- ns : 'http://specs.openid.net/auth/2.0' ,
56- claimed_id : 'https://steamcommunity.com/openid/id/' ,
57- identity : 'https://steamcommunity.com/openid/id/' ,
57+ if ( ! query [ 'openid.signed' ]
58+ || ! query [ 'openid.sig' ]
59+ ) {
60+ const error = createError ( {
61+ statusCode : 400 ,
62+ message : 'Steam login failed: Incomplete query.' ,
63+ } )
64+ if ( ! onError ) throw error
65+ return onError ( event , error )
5866 }
5967
60- const idRegex = / ^ h t t p s ? : \/ \/ s t e a m c o m m u n i t y \. c o m \/ o p e n i d \/ i d \/ ( \d + ) $ /
61- const steamIdCheck = idRegex . exec ( query [ 'openid.claimed_id' ] )
68+ const openIdCheck : Record < string , string > = {
69+ 'openid.ns' : 'http://specs.openid.net/auth/2.0' ,
70+ 'openid.mode' : 'check_authentication' ,
71+ 'openid.signed' : query [ 'openid.signed' ] ,
72+ 'openid.sig' : query [ 'openid.sig' ] ,
73+ }
6274
63- if (
64- query [ 'openid.op_endpoint' ] !== config . authorizationURL
65- || ! steamIdCheck
66- || query [ 'openid.ns' ] !== openIdCheck . ns
67- || ! query [ 'openid.claimed_id' ] ?. startsWith ( openIdCheck . claimed_id )
68- || ! query [ 'openid.identity' ] ?. startsWith ( openIdCheck . identity )
69- ) {
75+ for ( const signed of query [ 'openid.signed' ] . split ( ',' ) ) {
76+ if ( ! query [ `openid.${ signed } ` ] ) {
77+ const error = createError ( {
78+ statusCode : 400 ,
79+ message : 'Steam login failed: Incomplete query.' ,
80+ } )
81+ if ( ! onError ) throw error
82+ return onError ( event , error )
83+ }
84+ openIdCheck [ `openid.${ signed } ` ] = query [ `openid.${ signed } ` ]
85+ }
86+
87+ const auth_validation : string = await $fetch ( withQuery ( config ?. authorizationURL as string , openIdCheck ) )
88+
89+ const validRegex = / i s _ v a l i d : t r u e /
90+ const valid = validRegex . test ( auth_validation )
91+
92+ if ( ! valid ) {
7093 const error = createError ( {
7194 statusCode : 401 ,
7295 message : 'Steam login failed: Claimed identity is invalid.' ,
@@ -75,6 +98,9 @@ export function defineOAuthSteamEventHandler({ config, onSuccess, onError }: OAu
7598 return onError ( event , error )
7699 }
77100
101+ const idRegex = / ^ h t t p s ? : \/ \/ s t e a m c o m m u n i t y \. c o m \/ o p e n i d \/ i d \/ ( \d + ) $ /
102+ const steamIdCheck = idRegex . exec ( query [ 'openid.claimed_id' ] )
103+
78104 const steamId = steamIdCheck [ 1 ]
79105
80106 // TODO: improve typing
0 commit comments