Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
php-serialized-data
Advanced tools
Parse PHP serialized data with JavaScript.
PHP's serialize function doesn't have a spec, so I used the handy Kaitai Struct spec as reference instead
yarn add php-serialized-data
Or use it directly in the browser:
import { parse } from 'https://cdn.pika.dev/php-serialized-data';
import { parse } from 'php-serialized-data';
const data = parse( 'O:8:"stdClass":2:{s:3:"foo";s:3:"bar";s:16:"\u0000stdClass\u0000secret";s:3:"shh";}' );
/*
PHPObject(
className: 'stdClass',
value: Map( [
[ PHPString( value: 'foo' ), PHPString( value: 'bar' ) ],
[ PHPString( value: '\u0000stdClass\u0000secret' ), PHPString( value: 'shh' ) ],
] ),
)
*/
data.toJs();
/*
{ foo: 'bar' }
*/
data.toJs( { private: true } );
/*
{ foo: 'bar', secret: 'shh' }
*/
It even works with multi-byte data like emoji:
import { parse } from 'php-serialized-data';
const data = parse( 's:4:"🐊";' );
/*
PHPString( value: '🐊' )
*/
data.toJs();
/*
'🐊'
*/
The main parse()
function takes two parameters, the input string, and an options object.
parse( input, options? )
Option | Type | Default | Description |
---|---|---|---|
fixNulls | Boolean | false | Attempt to fix missing/broken null chars in input. Useful when the input was pasted from the clipboard. |
The fixNulls
option attempts to fix the following scenarios:
lambda_
, then the string is probably a serialized lambda function.*
, then the string is probably a protected property.Use the .toJs()
method on the output to convert to native JavaScript types.
value.toJs( options? )
The .toJs()
method accepts an options object:
Option | Type | Default | Description |
---|---|---|---|
private | Boolean | false | Include private & protected class properties |
detectArrays | Boolean | false | Output arrays where possible, instead of objects |
SplDoublyLinkedList
)FAQs
Parse PHP serialized data with JavaScript.
We found that php-serialized-data demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.