Skip to content
This repository has been archived by the owner on Aug 14, 2021. It is now read-only.

@jonallured: only allow jwt tokens from trusted apps #322

Merged
merged 2 commits into from
Oct 20, 2017

Conversation

cavvia
Copy link
Contributor

@cavvia cavvia commented Oct 19, 2017

It turns out gravity has an Auth API endpoint that deals out JWT tokens to untrusted apps (like force) with a short expiry. This can theoretically be used to produce valid JWT tokens for Bearden knowing only the Bearden application ID, which is a security problem.

While the Gravity API endpoint looks like a security hole, it can be useful for some apps who wish to allow access to a set of users from an untrusted app (like Impulse, which wants to allow some Force users access to their conversations inbox data, as Force is an untrusted app in this scheme).

We've decided it's up to the destination app to validate app roles in its auth if it wishes to restrict access to trusted apps. This is the case with Bearden, so I've added the additional checks in our auth method to ensure that the app which requested the token is trusted. We use 'roles' embedded in the JWT to determine whether an app is trusted (see gravity code).

cc @joeyAghion @mzikherman

@dblock
Copy link
Contributor

dblock commented Oct 20, 2017

This highlights the need for a shared middleware across Artsy for these! cc: @orta

I think the Gravity API is OK, it hands a token for a given app that can then be used to identify the user from gravity. That's authentication. Authorization is definitely the burden of this app and it should reject users it doesn't want.

I did raise this in #security on Slack btw. And please note that bearden is public, so this discussion is public as well.

@joeyAghion
Copy link

So far apps have simply used jwt rather than shared middleware. Maybe it can be an extension of https://github.com/artsy/artsy-auth, which is session-oriented and has hooks for asserting user roles explicitly, but could be extended to encapsulate the JWT validation and expose the embedded app and role data.

rescue JWT::DecodeError
payload = JWT.decode(token, secret).first
validate_payload(payload)
rescue JWT::DecodeError, NoMethodError
Copy link

Choose a reason for hiding this comment

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

NoMethodError seems too generic here.

Copy link
Member

@jonallured jonallured Oct 20, 2017

Choose a reason for hiding this comment

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

I agree - any reason you didn't like the return false unless line @cavvia?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree - Rubocop was giving me an AbcSize error, though I may have fixed that with the validate_payload extraction too. So can re-introduce and see if that works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is back now.

@@ -3,7 +3,7 @@
describe GraphqlController, type: :controller do
let(:jwt_token) do
JWT.encode(
{ aud: Rails.application.secrets.artsy_application_id },
{ aud: Rails.application.secrets.artsy_application_id, roles: 'trusted' },
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to see another test case here without the trusted role that shows it doesn't work - are you good with adding that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@jonallured jonallured left a comment

Choose a reason for hiding this comment

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

Thanks so much for opening this PR - I had no idea!

@jonallured jonallured merged commit 17e4841 into artsy:master Oct 20, 2017
@jonallured
Copy link
Member

Thank you @cavvia!! 🥇

@cavvia
Copy link
Contributor Author

cavvia commented Oct 20, 2017

@dblock @joeyAghion Agreed a shared middleware would be good. It would need to support these trusted app tokens. I think we can probably get it into artsy-auth, even if that is more focused on client devs.

@jonallured
Copy link
Member

FYI, I opened an issue over there artsy/artsy-auth#6 with some thoughts.

@jonallured
Copy link
Member

FYI, this is deployed to production.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants