Git Product home page Git Product logo

groan's Introduction

Description

groan is a PHP session file parser written in JavaScript.

Requirements

  • JavaScript (compatible with node.js)

Node.JS Examples

var fs = require('fs'),
    parser = require('groan');

/*
  ideally you should first ensure (session file's
  mtime + PHP's session.gc_maxlifetime) > Date.now() to ensure that the
  session has not expired yet
*/

// if it is still valid, continue on ...
fs.readFile('/tmp/sess_1234567890abcdef', function(err, b) {
  if (err) throw err;
  console.dir(parser(b.toString('utf8')));
  /*
     for a $_SESSION that contains:
        ["0"]=>
        string(3) "foo"
        ["a"]=>
        string(5) "apple"
        ["b"]=>
        bool(false)
        ["c"]=>
        array(3) {
          [0]=>
          int(17)
          [1]=>
          float(1.5)
          [2]=>
          string(1) "x"
        }
        ["d"]=>
        array(0) {
        }

    the parser will return an object that looks like:
      {
        0: 'foo',
        a: 'apple',
        b: false,
        c: [ 17, 1.5, 'x' ],
        d: []
      }
  */
});
var parser = require('groan');

var serialized = 'a:5:{i:0;s:3:"foo";s:1:"a";s:5:"apple";s:1:"b";b:0;s:1:"c";a:3:{i:0;i:17;i:1;d:1.5;i:2;s:1:"x";}s:1:"d";a:0:{}}';
console.dir(parser(serialized));

// output:
// { '0': 'foo', a: 'apple', b: false, c: [ 17, 1.5, 'x' ], d: [] }

Notes

  • References and recursion are not currently supported (currently returns undefined)

  • The parser assumes the session file data is in the valid PHP session serialized format

groan's People

Contributors

mscdex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

groan's Issues

TypeError: Cannot read property 'toLowerCase' of undefined at line 18 in groan.js

var v, type = o.str[o.pos].toLowerCase(), len, idelim;
^

TypeError: Cannot read property 'toLowerCase' of undefined
at __PHParseValue (/home/mysite/public_html/chat_server/node_modules /groan/groan.js:18:29)
at PHParse (/home/mysite/public_html/chat_server/node_modules/groan/ groan.js:4:12)
at /home/mysite/public_html/chat_server/index.js:75:17
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:446:3)

Issue with parsing session including MongoId

Hello,

I'm trying to use groan in a project and have an issue parsing the session data.
The session data contains a MongoId, which seems to fool the parser.

See this:
flash|a:2:{s:5:"email";s:19:"[email protected]";s:6:"events";a:1:{i:0;a:3:{s:9:"client_id";s:24:"4d00e8d6bf92fc8648000000";s:7:"user_id";s:6:"100003";s:3:"_id";C:7:"MongoId":24:{513f412ee77dddfb75000006}}}}user|a:1:{s:7:"user_id";s:6:"100003";}

This is a "valid" generate session from PHP when adding a MongoId to the session.
When reading session with groan, the key for the 'user' object is not 'user', it is 'MongoId":24:{513f412ee77dddfb75000006}}}}user'

Seems groan is not handling the serialization of MongoId properly.
See: http://php.net/manual/en/class.mongoid.php

MongoIds are serializable/unserializable. Their serialized form is similar to their string form:
C:7:"MongoId":24:{4af9f23d8ead0e1d32000000}

Unescaped quotes in a string causes a infinite loop

Hi,

We have been using groan for a node.js project and have discovered a problem. If we try to parse a php session that have a unescaped string groan enters a infinite loop. For example:

PHParse("session|s:44:"A test string containing "unescaped" quotes"");

will never return a value. This is of course a problem with our sessions and we have changed it to always have escaped strings but it is never the less dangerous since node.js will stop responding.

UTF8 chars in php session

I have a php session like that:

lastname|s:7:"Miklós";firstname|s:10:"Szörényi";gender|s:1:"1";

When groan parse it, I get this:

{ lastname: 'Miklós"', irstname: 'Szörényi";', nder: '1' }

The reason of parsing failure is the wrong length of the string value. The length of "Miklós" is 6, but the default php serialization say it's 7, because of the UTF chars.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.