4 ms·
> 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 att
by lucb1e 10y ago
> 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?
- wtetzner 10y ago> 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.
- tlrobinson 10y ago> 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)
- nulagrithom 10y ago> 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.
- lucb1e 10y agoCertainly, 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.
- s_q_b 10y agoYeah, 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.
- lucb1e 10y ago> 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...
- ars 10y ago> 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?
- SomeStupidPoint 10y agoThe 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.)