Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The original code was developed by Vlad Trushin. Breaking modifications were made by Romain Gaucher to create a less strict JSON parser. Additionally, a more typical interaction with the AST has been implemented.
Current modifications and features as of 2.1.6
include:
JsonDocument
root node and more formal AST structurejunker
set to true
):
JsonNode
Basic examples are available to show how to use this package.
The JSON parser accepts a superset of the JSON language:
// some comment
{
"key1": "value1", // some other comments
"key2": "value2",
,
,
/*
Oh dear! It's important to put this here.
And we love commas too!
And we're missing the closing brace...
*/
npm install json-ast
As of 2.1.0, the AST is defined with the following types:
[JsonNode] // Essentially an abstract class
position: [Position]
[JsonDocument] extends [JsonNode]
child: [?]*
comments: [JsonComment]*
[JsonValue] extends [JsonNode]
value: [?]
[JsonObject] extends [JsonNode]
properties: [JsonProperty]*
comments: [JsonComment]*
[JsonProperty] extends [JsonNode]
key: [JsonKey]
value: [?]*
[JsonKey] extends [JsonValue]
[JsonArray]
items: *
comments: [JsonComment]*
[JsonComment] extends [JsonValue]
[JsonString] extends [JsonValue]
[JsonNumber] extends [JsonValue]
[JsonTrue] extends [JsonValue]
[JsonFalse] extends [JsonValue]
[JsonNumber] extends [JsonValue]
All the types exists in src/ast.js.
import {parse, Visitor, AST} from 'json-ast';
// The visitor can stop at any time by assigning `Visitor.stop = true`
class MyVisitor extends Visitor {
constructor() {
super();
this.comments = [];
}
comment(commentNode) {
this.comments.push(commentNode.value);
}
};
const JSON_BUFFER = `// Some comment
{
"key": "value"
`;
// `verbose` will include the position in each node
const ast = parse(JSON_BUFFER, {verbose: true, junker: true});
assert(ast instanceof AST.JsonDocument);
const visitor = new MyVisitor();
ast.visit(visitor);
assert.deepEqual(visitor.comments, [" Some comment"]);
// One can also the `JsonNode.toJSON` static method to convert to a JavaScript object
const obj = JsonNode.toJSON(ast);
assert(obj.key === 'value');
The second argument of the parse
function takes an object with the following settings:
verbose
: include positions in each AST node, true
by defaultjunker
: enables an error recovery mode, false
by defaultMIT Vlad Trushin and Romain Gaucher
FAQs
JSON parser AST utilities
The npm package json-ast receives a total of 63 weekly downloads. As such, json-ast popularity was classified as not popular.
We found that json-ast 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.