Skip to content

Commit 17708af

Browse files
Encode userId in updateUser path
updateUser interpolated payload.userId raw into the PUT path, leaving the same path-traversal primitive open. Encode it and add a regression test.
1 parent 088d805 commit 17708af

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/user-management/user-management.spec.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,20 @@ describe('UserManagement', () => {
20332033
});
20342034
});
20352035

2036+
it('encodes the userId so it cannot escape the route template', async () => {
2037+
fetchOnce(userFixture);
2038+
2039+
await workos.userManagement.updateUser({
2040+
userId: '../../organizations/org_01TARGET?',
2041+
firstName: 'Dane',
2042+
});
2043+
2044+
const url = new URL(fetchURL() as string);
2045+
expect(url.pathname).toBe(
2046+
'/user_management/users/..%2F..%2Forganizations%2Forg_01TARGET%3F',
2047+
);
2048+
});
2049+
20362050
describe('when only one property is provided', () => {
20372051
it('sends a updateUser request', async () => {
20382052
fetchOnce(userFixture);

‎src/user-management/user-management.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ export class UserManagement {
10081008
*/
10091009
async updateUser(payload: UpdateUserOptions): Promise<User> {
10101010
const { data } = await this.workos.put<UserResponse>(
1011-
`/user_management/users/${payload.userId}`,
1011+
`/user_management/users/${encodeURIComponent(payload.userId)}`,
10121012
serializeUpdateUserOptions(payload),
10131013
);
10141014

0 commit comments

Comments
 (0)