Skip to content

[SECURITY] Set Auth-scheme preference #33156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 6, 2018
Merged

Conversation

bizybot
Copy link
Contributor

@bizybot bizybot commented Aug 27, 2018

Some browsers (eg. Firefox) behave differently when presented with
multiple auth schemes in 'WWW-Authenticate' header. The expected
behavior is that browser select the most secure auth-scheme before
trying others, but Firefox selects the first presented auth scheme and
tries the next ones sequentially. As the browser interpretation is
something that we do not control, we can at least present the auth
schemes in most to least secure order as the server's preference.

This commit modifies the code to collect and sort the auth schemes
presented by most to least secure. The priority of the auth schemes is
fixed, the lower number denoting more secure auth-scheme.
The current order of schemes based on the ES supported auth-scheme is
[Negotiate, Bearer,Basic] and when we add future support for
other schemes we will need to update the code. If need be we will make
this configuration customizable in future.

Unit test to verify the WWW-Authenticate header values are sorted by
server preference as more secure to least secure auth schemes.
Tested with Firefox, Chrome, Internet Explorer 11.

Closes#32699

Some browsers (eg. Firefox) behave differently when presented with multiple
auth schemes in 'WWW-Authenticate' header. The expected behavior is that browser
select the most secure auth scheme before trying others, but Firefox selects the
first presented auth scheme and tries the next one's sequentially. As the
interpretation is something we do not control, we can at least present
the auth schemes in most to least secure order as server's preference.

This commit adds the changes to collect and sort the auth schemes presented
by most to least secure. We support 'negotiate', 'bearer' and 'basic' schemes
and the order is hardcoded with no customization. If there are user requests
we will make this configurable.

Unit test to verify the `WWW-Authenticate` header values are sorted by server
preference as more secure to least secure auth schemes.
Testing done with Firefox, Chrome, Internet Explorer 11.

Closes#32699
@bizybot bizybot added >bug review v7.0.0 :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) v6.5.0 labels Aug 27, 2018
@bizybot bizybot requested review from tvernum and jaymode August 27, 2018 04:26
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security

@jaymode jaymode added >enhancement and removed >bug labels Aug 28, 2018
@@ -424,4 +439,30 @@ public void testGetFieldFilterSecurityEnabledLicenseNoFLS() throws Exception {
assertNotSame(MapperPlugin.NOOP_FIELD_FILTER, fieldFilter);
assertSame(MapperPlugin.NOOP_FIELD_PREDICATE, fieldFilter.apply(randomAlphaOfLengthBetween(3, 6)));
}

public void testDefaultFailureHandlerFailedAuthenticationRespondsWithSortedWWWAuthenticateHeaderValues() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not put this in DefaultAuthenticationFailureHandlerTests and then it doesn't need such a long name? Like we can just have testSortsWWWAuthenticateHeaderValues in that class

Yogesh Gaikwad added 2 commits August 29, 2018 10:35
Moved the logic to sort auth schemes in the failure
handler constructor and the test to failure handler tests.
private void assertWWWAuthenticateWithSchemes(final ElasticsearchSecurityException ese, final String... schemes) {
assertThat(ese.getHeader("WWW-Authenticate").size(), is(schemes.length));
// Auth scheme are ordered as more secure to least secure
Arrays.sort(schemes, (o1, o2) -> authSchemePriority(o1).compareTo(authSchemePriority(o2)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this explicit? ie there could be a bug in authSchemePriority so we should validate Negotiate first, then bearer, then basic

@bizybot
Copy link
Contributor Author

bizybot commented Sep 4, 2018

Hi @jaymode, I have addressed your review comments, please review when you get some time. Thank you.

Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one minor comment, otherwise LGTM

final String bearerAuthScheme = "Bearer realm=\"" + XPackField.SECURITY + "\"";
final String negotiateAuthScheme = randomFrom("Negotiate", "Negotiate Ijoijksdk");
final Map<String, List<String>> failureResponeHeaders = new HashMap<>();
failureResponeHeaders.put("WWW-Authenticate", Arrays.asList(basicAuthScheme, bearerAuthScheme, negotiateAuthScheme));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should randomize the order of this list, ie Collections.shuffle(list, random())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, addressed this.

@bizybot bizybot merged commit ee73bc2 into elastic:master Sep 6, 2018
@bizybot bizybot deleted the fix/32699 branch September 6, 2018 22:46
bizybot added a commit that referenced this pull request Sep 6, 2018
Some browsers (eg. Firefox) behave differently when presented with
multiple auth schemes in 'WWW-Authenticate' header. The expected
behavior is that browser select the most secure auth-scheme before
trying others, but Firefox selects the first presented auth scheme and
tries the next ones sequentially. As the browser interpretation is
something that we do not control, we can at least present the auth
schemes in most to least secure order as the server's preference.

This commit modifies the code to collect and sort the auth schemes
presented by most to least secure. The priority of the auth schemes is
fixed, the lower number denoting more secure auth-scheme.
The current order of schemes based on the ES supported auth-scheme is
[Negotiate, Bearer,Basic] and when we add future support for
other schemes we will need to update the code. If need be we will make
this configuration customizable in future.

Unit test to verify the WWW-Authenticate header values are sorted by
server preference as more secure to least secure auth schemes.
Tested with Firefox, Chrome, Internet Explorer 11.

Closes#32699
@azasypkin
Copy link
Member

Some browsers (eg. Firefox) behave differently when presented with
multiple auth schemes in 'WWW-Authenticate' header. The expected
behavior is that browser select the most secure auth-scheme before
trying others, but Firefox selects the first presented auth scheme and
tries the next ones sequentially. As the browser interpretation is
something that we do not control, we can at least present the auth
schemes in most to least secure order as the server's preference.

@bizybot, have we filed a bug against Firefox (assuming there was no existing one)? Can you please share a link? Thanks!

@tvernum
Copy link
Contributor

tvernum commented Sep 24, 2018

@azasypkin
See #32699 (comment)

@azasypkin
Copy link
Member

See #32699 (comment)

Thanks! Reported: 8 years ago 😞

@tvernum
Copy link
Contributor

tvernum commented Sep 24, 2018

Yeah, we decided it probably wasn't worth waiting on an upstream fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) v6.5.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected basic auth prompt with SPNEGO (kerberos) enabled in browser
6 participants