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:
Michael Muller 2021-03-23 08:50:56 -04:00 committed by GitHub
parent b6e4ff4e80
commit dc88b48772
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 23 deletions

View file

@ -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);