Skip to content

Commit

Permalink
fix: prevent infinite redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyeh committed Oct 26, 2023
1 parent b473de5 commit dc20a6f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions next/api/src/controller/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class UserController {
@Get(':id')
@UseMiddlewares(auth, staffOnly)
@ResponseBody(UserResponse)
findOne(@Param('id', new FindModelPipe(User, {useMasterKey: true})) user: User) {
findOne(@Param('id', new FindModelPipe(User, { useMasterKey: true })) user: User) {
return user;
}

Expand Down Expand Up @@ -214,7 +214,10 @@ export class UserController {
}

@Post('tds/token')
async exchangeJwt(@Ctx() ctx: Context, @Body(new ZodValidationPipe(exchangeSchema)) data: ExchangeData) {
async exchangeJwt(
@Ctx() ctx: Context,
@Body(new ZodValidationPipe(exchangeSchema)) data: ExchangeData
) {
const { jwt } = data;
const { appId, sub } = transformToHttpError(() =>
getVerifiedPayloadWithSubRequired(
Expand All @@ -228,9 +231,9 @@ export class UserController {
)
);

if (appId === 'nxfahljt0g0tzsjwrw') {
const url = new URL(ctx.url, 'https://support.xd.com')
ctx.response.status = 307;
if (ctx.hostname !== 'support.xd.com' && appId === 'nxfahljt0g0tzsjwrw') {
const url = new URL(ctx.url, 'https://support.xd.com');
ctx.response.status = 307;
ctx.response.set('Location', url.toString());
ctx.response.body = '';
ctx.res.end();
Expand Down

0 comments on commit dc20a6f

Please sign in to comment.