Skip to content

Commit 89cfa87

Browse files
authored
Fix permissions for SessionOutput.impersonator (#3171)
1 parent 18f2dda commit 89cfa87

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/components/authentication/session.resolver.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '../../common';
1515
import { ConfigService, ILogger, Loader, LoaderOf, Logger } from '../../core';
1616
import { Power, Privileges } from '../authorization';
17-
import { User, UserLoader } from '../user';
17+
import { User, UserLoader, UserService } from '../user';
1818
import { AuthenticationService } from './authentication.service';
1919
import { SessionOutput } from './dto';
2020
import { SessionInterceptor } from './session.interceptor';
@@ -26,6 +26,7 @@ export class SessionResolver {
2626
private readonly privileges: Privileges,
2727
private readonly config: ConfigService,
2828
private readonly sessionInt: SessionInterceptor,
29+
private readonly users: UserService,
2930
@Logger('session:resolver') private readonly logger: ILogger,
3031
) {}
3132

@@ -105,12 +106,18 @@ export class SessionResolver {
105106
})
106107
async impersonator(
107108
@Parent() { session }: SessionOutput,
108-
@Loader(UserLoader) users: LoaderOf<UserLoader>,
109109
): Promise<User | null> {
110110
if (session.anonymous || !session.impersonator) {
111111
return null;
112112
}
113-
return await users.load(session.impersonator.userId);
113+
// Edge case: Load the impersonator, as the impersonator, rather than the impersonatee.
114+
// They should still be able to see their own props from this field.
115+
// Otherwise, it could be that the impersonatee can't see the impersonator's roles,
116+
// and now the UI can't stop impersonating because it doesn't know the impersonator's roles.
117+
return await this.users.readOne(
118+
session.impersonator.userId,
119+
session.impersonator, // instead of `session`
120+
);
114121
}
115122

116123
@ResolveField(() => [Power], { nullable: true })

0 commit comments

Comments
 (0)