mirror of
https://github.com/google/nomulus.git
synced 2025-07-08 12:13:19 +02:00
Disallow admin triggering of internal endpoints (#1030)
* Disallow admin triggering of internal endpoints Stop simply relying on the presence of the X-AppEngine-QueueName as an indicator that an endpoint has been triggered internally, as this allows admins to trigger a remote execution vulnerability. We now supplement this check by ensuring that there is no authenticated user. Since only an admin user can set these headers, this means that the header must have been set by an internal request. Tested: In addition to the new unit test, verified on Crash that: - Internal requests are still getting authenticated via the internal auth mechanism. - Admin requests with the X-AppEngine-QueueName header are rejected as "unauthorized." * Reformatted.
This commit is contained in:
parent
b6e4ff4e80
commit
dc88b48772
2 changed files with 24 additions and 23 deletions
|
@ -117,7 +117,7 @@ class RequestAuthenticatorTest {
|
|||
|
||||
private RequestAuthenticator createRequestAuthenticator(UserService userService) {
|
||||
return new RequestAuthenticator(
|
||||
new AppEngineInternalAuthenticationMechanism(),
|
||||
new AppEngineInternalAuthenticationMechanism(fakeUserService),
|
||||
ImmutableList.of(
|
||||
new OAuthAuthenticationMechanism(
|
||||
fakeOAuthService,
|
||||
|
@ -173,6 +173,16 @@ class RequestAuthenticatorTest {
|
|||
assertThat(authResult.get().userAuthInfo()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInternalAuth_failForAdminUser() {
|
||||
when(req.getHeader("X-AppEngine-QueueName")).thenReturn("__cron");
|
||||
fakeUserService.setUser(testUser, true /* isAdmin */);
|
||||
|
||||
Optional<AuthResult> authResult = runTest(fakeUserService, AUTH_INTERNAL_OR_ADMIN);
|
||||
|
||||
assertThat(authResult).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAnyUserAnyMethod_notLoggedIn() {
|
||||
Optional<AuthResult> authResult = runTest(fakeUserService, AUTH_ANY_USER_ANY_METHOD);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue