12

A user logs in using default Laravel authentication, which puts an encrypted cookie in the browser, and saves the session in the database.

The user moves to a classic asp page, where I check the cookie value, get the hash, and call the laravel app back passing the session id hash.

Then I use that in laravel to see if there's an active session for that id, and if so I return true, so the user can be logged in, in classic asp.

On each page request in the classic app, I check the last_updated_time in the db and update it on each page. All logging in and out is done in laravel, and classic relies on the database to see if a session is active.

I would also call a public url to get sessions variables and add session variables using laravel, since it's all encrypted and using classic asp for this would be hard.

The only risk I see is session highjacking, but I don't think it's a higher risk than usual.

Is it important to lockdown the laravel URL I call to check if it's a valid session?

Am I missing a security hole here?

Positonic
  • 9,151
  • 14
  • 57
  • 84

4 Answers4

7

Is this method secure?

From what you've stated you probably haven't opened up any security holes. The session cookie is not itself encrypted on the users machine, but you are making sure it is encrypted between their machines and yours, as well as between each of your machines. You should make sure you've set the Secure Flag to help prevent the cookie being accidentally sent over traditional unencrypted transport (HTTP), but as stated, this doesn't effect storing the cookie itself.

That being said, you are essentially hijacking your own users sessions. While a hole might not be introduced now, you are potentially weakening the overall system, which could lead to hole in the future.

Is there a better way to do it?

This might well be a dumb question, but are you sure you need the session? If you're juggling credentials between servers, it sounds more like you want to use Access Tokens and scrap the session.

Using Access Tokens is similar to using sessions, but you need to make your services stateless. This means your no longer storing information about the logged in user any specific machine so you'll need to pull anything you need from the database every time they hit a server requiring that information.

This is a good thing in the long run as it's much easier to scale your services when you don't need to worry so much about where the session is and what's inside it.

OAuth 2.0 is widely used standard (Facebook, Twitter, Google), and was specifically designed to be easy to use. The RFC is complex, but there's a log of good guides out there don't worry.

The one slight down side (if you can call it that) to OAuth 2, is that it MUST happen over an encrypted connection. If your use case can not guarantee encryption over SSL or (preferably) TLS, then you should use OAuth 1.0 (WITH revision A) instead.

This is due to the fact that OAuth 2.0 exposes it's "secret" token in requests, where as OAuth 1.0 only ever uses it to provide a signature hash. If you take this route it's advisable to use someone else's library as the hash is very, specific.

Further Improvement

(Note: This section added after the answer was accepted)

One system I've been exploring recently is Json Web Tokens. These store information about the user to save each machine repeatedly looking it up in a database. Because the token is hashed with a secret, you can be sure that, so long as your secret isn't exposed, a valid token represents a successfully logged in user, without having to touch the database.

You should avoid putting anything too personal in the tokens if possible. If you must store private or secret information in the token, you can encrypt it, or you can use a reverse caching proxy to exchange the JWT for a traditional security token. This may initially seem to defeat the purpose, but it means some of your services may not need database access at all.

Community
  • 1
  • 1
DanielM
  • 6,380
  • 2
  • 38
  • 57
0

I'm no security expert but I don't see an issue with this. The packaged Laravel database session handler works the same way. The cookie contains a hash that references a record in the database. The session data is base64 encoded but that's neither here nor there. I think you could actually avoid rolling your own and just use Laravel's DatabaseSessionHandler.

Illuminate/Session/DatabaseSessionHandler

... I just read a little deeper into your question and noticed the part about the public URL to set and retrieve session data. I think this is a really bad idea. Mostly because it will provide an open door to the end user allowing them to read and write session data. This can only end badly.

Like I said above, the data is only base64 encoded so I believe you'll be able to parse, read and write that to your hearts content within asp.

Edit

Ok... I think this is the last edit. The data is php serialized and then base64 encoded. This question looks like it may help you to that end. If it doesn't and an API endpoint is the only way, find some way to block the end user from accessing it.

Community
  • 1
  • 1
Collin James
  • 9,062
  • 2
  • 28
  • 36
0

Aside from session-hijacking, no. This is the standard way applications interact on a internal basis. Of course there might be a better way to get at the data if you choose a different type of session store other than your database, Memcached for instance.

geggleto
  • 2,605
  • 1
  • 15
  • 18
0

There are couple of things that can be done.

  • Make the channel HTTPS. It will make almost impossible to sniff on your transport layer.
  • Rather than making interactions with your cookie, you could use a JWT to get this task done. Which will help you to use the existing functionality in your system while connecting with ASP system as well. You can write a small REST web service which allows ASP to connect. You could use this lib. You can refer this article which will give you an idea how it should be done.

Please let me know if you need more information.

Techie
  • 44,706
  • 42
  • 157
  • 243
  • I don't think that HTTPS will protect against an attacker who is running the client on their machine and using a debugging proxy to view the data traffic. I still like HTTPS everywhere, I just don't think it protects sniffing as well as you state. – Neil Smithline Apr 19 '15 at 22:28
  • https adds a encryption to the transport layer. – Techie Apr 20 '15 at 15:05