6

I am working on writing a private REST API with Play! that I will make calls to from a mobile application and I am confused about how to keep it secure.

When working through the Yet Another Blog Engine example in Play!'s documentation, I worked through their authentication example, and it deals with logging in through a browser. From what I understand about Play!'s Secure module, it helps with browser sessions. Additionally, every StackOverflow question I have seen has been involved with an administration module on the web and the questions have been pertaining to sessions as well.

Does the Play! framework have any built in mechanism to prevent session hijacking?

Enforce Https routing for login with play framework

My current understanding of how the security should work:

  • The mobile app "logs in" to the web app and obtains some kind of token
  • With each subsequent call the token is appended to the end of the API call
  • If the mobile user "logs out" or the token expires, the web app removes the token
  • Every API call uses HTTPS in order to maintain security

Is it possible for me to make an HTTP request from the mobile application to the web application I create using Play! Framework while keeping it secure?

Am I approaching the whole situation incorrectly?

This is the first Play! app I have created and this is the first time I have used Heroku. I am not too far in that I would be opposed to switching to something else if it were significantly easier/more efficient/better suited to solve this problem.

EDIT: Also, in Play!'s YABE tutorial, it seems like they check the password in plain text. Just from a general standpoint, how is that not a security issue?

EDIT 2: I have looked over OAuth provider information and it seems to solve the problem. My only apprehension with it is that v2.0 has known security flaws and v1.0 seems complicated to implement for a situation where all I need is a secure connection between a mobile app and a web app. If I were to make every call require SSL, could I make each Play method just take username and password as parameters and disregard OAuth completely?

Community
  • 1
  • 1
eliot
  • 1,319
  • 1
  • 14
  • 33
  • 2
    "in Play!'s YABE tutorial, it seems like they check the password in plain text" - depends what you mean by plain text. If it's over HTTPS, it's not a problem to send the password in a request. If they're storing the password in the database in plain text, that's bad. Shame when tutorials completely ignore basic security "for simplicity". – Nick Mar 09 '13 at 20:09
  • From the links you've used it looks like you're using Play 1.x. Any reason you're not going with 2.x? – Nick Mar 09 '13 at 20:24
  • Heroku by default uses Play 1.2.4. I don't know of a reason to upgrade it as of right now and time is the most important thing in regards to the mobile app. – eliot Mar 09 '13 at 20:43

1 Answers1

2

Your example of having a mobile application authorize itself with a web application is achieved with an authorization framework like OAuth. This allows the web app to let the user login then issue an access token to the mobile app for making requests as that user, without the mobile app having to deal with the user's password.

Have a look at an OAuth provider module for Play. If you Google, you might find an OAuth client module for Play, but that's for the other side of OAuth, allowing your web app to authorize against a 3rd party provider. You'd then use an OAuth client library in your mobile app to deal with acquiring an access token.

It could even be a generic Java libary for OAuth - the Play 2.0 documentation for OAuth states that it hasn't provided an OAuth 2.0 module because it's simple enough not to even need a library. However there are a few Java libraries available.

Here's a project where somebody's put together some OAuth provider stuff with Play (referenced from this forum post):

https://github.com/mashup-fm/playframework-oauthprovider

Nick
  • 11,475
  • 1
  • 36
  • 47
  • I looked at OAuth initially but I think I got discouraged because I was only finding the client module information. And in your last sentence, you meant to say mobile app, right? So I'd have the OAuth provider in the web app (Play!) and the OAuth client in the mobile app? – eliot Mar 09 '13 at 20:11
  • Yes, sorry, fixed. Also see my addition - it doesn't necessarily need to be a Play module, since it's a fairly simple workflow that you could roll yourself. – Nick Mar 09 '13 at 20:14
  • Okay, I have looked over OAuth provider information and it seems to solve the problem. My only apprehension with it is that v2.0 has known security flaws and v1.0 seems complicated to implement for a situation where all I need is a secure connection between a mobile app and a web app. If I were to make every call require SSL, could I make each Play method just take username and password as parameters and disregard OAuth completely? – eliot Mar 09 '13 at 20:40
  • If it's over SSL and you're comfortable with storing the user's username and password unprotected on the device, you could do that. You would probably implement it as a Play @Before interceptor rather than doing the check on every individual controller method. – Nick Mar 09 '13 at 21:11
  • 1
    If you're going to go the username/password route (mentioned above) please be kind to the users and send username/hash instead. There's rarely ever a reason to store a password in plain text and you really don't need any two-way encryption for this (like AES) – hodgesmr Mar 11 '13 at 01:11
  • Yes, good point. I should've mentioned that as a possibility since OP has control of the server side. – Nick Mar 12 '13 at 21:41