Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lock down the query props even more #34

Merged
merged 1 commit into from
Oct 29, 2024
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
2 changes: 2 additions & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export const VALID_ID_SELECT = `${VALID_NONCE}/identifier_select`;
export const VALID_IDENTITY_ENDPOINT = 'https://steamcommunity.com/openid/id';
export const VALID_OPENID_ENDPOINT = 'https://steamcommunity.com/openid/login';
export const PLAYER_SUMMARY_URL = 'https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2';
export const VALID_ASSOC_HANDLE = '1234567890';
export const VALID_SIGNED_FIELD = 'signed,op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle';
16 changes: 14 additions & 2 deletions src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { SteamOpenIdError } from './error';
import {
OPENID_QUERY_PROPS,
PLAYER_SUMMARY_URL,
VALID_ASSOC_HANDLE,
VALID_IDENTITY_ENDPOINT,
VALID_ID_SELECT,
VALID_NONCE,
VALID_OPENID_ENDPOINT,
VALID_SIGNED_FIELD,
} from './constant';
import {
SteamOpenIdUserProfile,
Expand Down Expand Up @@ -269,15 +271,25 @@ export class SteamOpenIdStrategy<
*/
protected isQueryValid(query: ParsedUrlQuery): query is SteamOpenIdQuery {
for (const key of OPENID_QUERY_PROPS) {
// Every prop has to be present
if (!query[key]) {
return false;
}
}

if (query['openid.ns'] != VALID_NONCE) return false;
if (query['openid.op_endpoint'] != VALID_OPENID_ENDPOINT) return false;
for (const key of Object.keys(query)) {
// Do not allow any extra properties
if (!OPENID_QUERY_PROPS.includes(key as any)) {
return false;
}
}

if (query['openid.ns'] !== VALID_NONCE) return false;
if (query['openid.op_endpoint'] !== VALID_OPENID_ENDPOINT) return false;
if (query['openid.claimed_id'] !== query['openid.identity']) return false;
if (!this.isValidIdentity(query['openid.claimed_id'])) return false;
if (query['openid.assoc_handle'] !== VALID_ASSOC_HANDLE) return false;
if (query['openid.signed'] !== VALID_SIGNED_FIELD) return false;
return query['openid.return_to'] == this.returnURL;
}

Expand Down
3 changes: 3 additions & 0 deletions test/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
OPENID_QUERY_PROPS,
VALID_OPENID_ENDPOINT,
PLAYER_SUMMARY_URL,
VALID_SIGNED_FIELD,
} from '../src';
import { RETURN_URL, getISODate, query } from './setup/data';

Expand Down Expand Up @@ -414,6 +415,8 @@ describe('SteamOpenIdStrategy Unit Test', () => {
'openid.identity': VALID_ID_SELECT,
'openid.claimed_id': VALID_ID_SELECT,
'openid.return_to': RETURN_URL,
'openid.assoc': '',
'openid.signed': VALID_SIGNED_FIELD,
};

url.searchParams.forEach((value, name) => {
Expand Down
Loading