News for hackers. Stuff that matters.
Re:Parsing JSON is a Minefield by lucb1e on Wednesday October 26, 2016 @11:08AM (#12797038)
> Well, first and most obviously, if you are thinking of rolling your own JSON parser, stop and seek medical attention.

Been there done that. (The medical attention, I mean.) Worked just fine. The article makes it sound extremely difficult, but 100% of the article is about edge cases that rarely happen with normal encoders and can often be ignored (e.g. who cares if you escape your tab character?).

> consider what happens when the code opens a session, sets the session username, then parses some input JSON before the password is evaluated

Edit: I responded more elaborately on the unlikelihood of this, but honestly, I can't come up with a single conceivable scenario. How would you decode part of the JSON and only parse the password bit later?

Re:Parsing JSON is a Minefield by s_q_b on Wednesday October 26, 2016 @11:45AM (#12797422)
Yeah, the whole idea is a terrible practice, but it is used in industry surprisingly often. People think that PHP's session lock will save them, seeing the potential race condition but not the decode failure.

The scenario is typically username-password-parameters passed as three variables via POST. The offending developer parses all three variables up front for simplicity:

The session user is created from the POST username, the POST password is input sanitized and put in a variable, then the parameters are parsed as JSON. The attacker POSTs a valid user, a valid (but incorrect) password, and malformed JSON.

The login code reads the variables from POST, opens the session, and dies on the JSON decode.

Hint: this bug exists in the wild on a massively deployed framework. I'm working up a responsible disclosure on that one now.

Re:Parsing JSON is a Minefield by lucb1e on Wednesday October 26, 2016 @11:52AM (#12797491)
> Hint: this bug exists in the wild on a massively deployed framework. I'm working up a disclosure on that one now.

Alright you win. I'm curious to know which one it was after it's fixed!

I really didn't expect this to exist...

Re:Parsing JSON is a Minefield by ars on Wednesday October 26, 2016 @12:34PM (#12797921)
> and dies on the JSON decode

That's the part I don't get. Once the code dies it's done. What exactly can you do now, if no code is even running?

Re:Parsing JSON is a Minefield by SomeStupidPoint on Wednesday October 26, 2016 @12:59PM (#12798199)
The steps are the following:

1. Parse user.

2. Parse password.

3. Create session object from user and password.

4. Parse JSON. (Crashes here.)

5. Update session and do some other security stuff.

The problem is that they're creating a persistent session object ahead of when the JSON parameters are being decoded, which leaves a (partially initialized, persisting-outside-of-function) session object without having gone through the full authentication flow.

The problem is that they're creating permanent objects ahead of a full validation on the data necessary to actually properly initialize the object.

(I think the OP may have been a little vague because that's probably specific enough to identify the vuln with a scanner and a hunch.)

Re:Parsing JSON is a Minefield by umbrai_nation on Wednesday October 26, 2016 @10:16PM (#12802442)
Wait, so it creates a privileged session before verifying the password? That's your problem right there. A crash in the JSON processor (or anywhere else) is a minor blip compared to this godzilla bug of granting access before it's been earned.
Re:Parsing JSON is a Minefield by mathw on Thursday October 27, 2016 @04:25AM (#12803603)
Spot on! But if the JSON parser couldn't crash on malformed input, that kind of whopping mistake would be a lot harder to exploit.
Re:Parsing JSON is a Minefield by mort96 on Wednesday October 26, 2016 @04:48PM (#12800370)
Remember, it's PHP. Code will be running again on the next request. Only the process (or thread or whatever) handling the request with the invalid JSON crashes, and it only crashes after producing a persistent session; the next request, a different process/thread/whatever will run code, but the session from the previous request still exists.
Re:Parsing JSON is a Minefield by KayEss on Wednesday October 26, 2016 @11:17PM (#12802673)
I still don't get it. The browser gets the session cookie even though the request processing crashed? Or does another request manage to pick up the session that was dropped from the crashed request?

I don't do PHP. It just sounds incredible to me that so little isolation seems to exist.

Re:Parsing JSON is a Minefield by pbowyer on Wednesday October 26, 2016 @01:49PM (#12798714)
Thanks for the extra explanation - I too doubted this could exist (surely the session existing alone isn't enough to assume a user is authenticated - need a variable set & checked every request?) but I see that it could.

I look forward to the disclosure to understand more about this - and check that the frameworks I use don't have this problem.

Re:Parsing JSON is a Minefield by nulagrithom on Wednesday October 26, 2016 @11:32AM (#12797282)
> edge cases that rarely happen with normal encoders and can often be ignored

I've found that "edge cases that rarely happen" are typically 90% of my major headaches.

Re:Parsing JSON is a Minefield by lucb1e on Wednesday October 26, 2016 @11:51AM (#12797480)
Certainly, edge cases are a source of pain. Luckily I mentioned that even if you ignore most of these edge cases (as a parser) the data will come out just fine.
Re:Parsing JSON is a Minefield by wtetzner on Wednesday October 26, 2016 @11:13AM (#12797081)
> Setting the session flag for "this user is logged in" before checking (or even decoding!) the password seems rather backwards to me.

Yeah, that seems like a problem regardless of whether or not you're parsing JSON.

Re:Parsing JSON is a Minefield by rch on Wednesday October 26, 2016 @11:19AM (#12797146)
Probably a symptom of the PHP multiverse: anything that can happen, has happened.
Re:Parsing JSON is a Minefield by oblio on Wednesday October 26, 2016 @01:53PM (#12798769)
And will continue to happen in a Wordpress setup somewhere.
Re:Parsing JSON is a Minefield by tlrobinson on Wednesday October 26, 2016 @11:20AM (#12797147)
> How would you decode part of the JSON and only parse the password bit later?

Not saying it's common or likely in this scenario, but there are streaming JSON parsers (like SAX for XML)