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.
A simple Javascript library implementing the JSON Reference and the JSON Pointer specifications.
$ npm install jsonref
dataOrUri
, the data to parse or a fully qualified URI to pass to retriever
to download the dataoptions
(optional), parsing options, the following optional properties are supported:
scope
, the current resolution scope (base href) of URLs and paths.store
, an object to use to cache resolved id
and $ref
values. If no store is passed,
one is automatically created. Pass a store
if you are going to parse several objects or URIs referencing
the same id
and $ref
values.retriever
, a function accepting a URL in input and returning a promise resolved to an object
representing the data downloaded for the URI. Whenever a $ref
to a new URI is found, if the URI is not
already cached in the store in use, it'll be fetched using this retriever
. If not retriever
is passed
and a URI needs to be downloaded, a no_retriever
exception is thrown.The function returns a Promise resolving to the parsed data, with all $ref
instances resolved.
retriever
using fetch
function retriever(url) {
var opts = {
method: 'GET',
credentials: 'include'
};
return fetch(url, opts).then(function(response) {
return response.json();
});
}
retriever
using request
var request = require('request');
function retriever(url) {
return new Promise(function(resolve, reject) {
request({
url: url,
method: 'GET',
json: true
}, function(err, response, data) {
if (err) {
reject(err);
} else if (response.statusCode !== 200) {
reject(response.statusCode);
} else {
resolve(data);
}
});
});
}
data
, the object to transverse using JSON Pointer.path
, either a string (#/prop1/prop2
) or an array of path components ([ "#", "prop1", "prop2" ]
or [ "prop1", "prop2" ]
).Returns the data requested
parse({
"id": "http://my.site/myschema#",
"definitions": {
"schema1": {
"id": "schema1",
"type": "integer"
},
"schema2": {
"type": "array",
"items": { "$ref": "schema1" }
}
}
}).then(function(data) {
console.log(JSON.stringify(data, null, 2));
});
The output is:
{
"id": "http://my.site/myschema#",
"definitions": {
"schema1": {
"id": "schema1",
"type": "integer"
},
"schema2": {
"type": "array",
"items": {
"id": "schema1",
"type": "integer"
}
}
}
}
parse({
"allOf": [
{ "$ref": "http://json-schema.org/draft-04/schema#" },
{
"type": "object",
"properties": {
"documentation": {
"type": "string"
}
}
}
]
}, null, {
retriever: retriever
}).then(function(data) {
console.log(JSON.stringify(data, null, 2));
});
The library will call retriever("http://json-schema.org/draft-04/schema#")
to download the external
reference. If no retriever
is passed, the returned value is a rejected Promise, with a no_retriever
exception.
var store = {};
parse({
"id": "http://my.site/myschema#",
"definitions": {
"schema1": {
"id": "schema1",
"type": "integer"
},
"schema2": {
"type": "array",
"items": { "$ref": "schema1" }
}
}
}, null, {
store: store
}).then(function(data) {
console.log(JSON.stringify(store, null, 2));
});
After parsing, the contents of the store are:
{
"http://my.site/myschema#": {
"id": "http://my.site/myschema#",
"definitions": {
"schema1": {
"id": "schema1",
"type": "integer"
},
"schema2": {
"type": "array",
"items": {
"id": "schema1",
"type": "integer"
}
}
}
},
"http://my.site/schema1#": {
"id": "schema1",
"type": "integer"
}
}
FAQs
Javascript References ($ref) and Pointers library
The npm package jsonref receives a total of 13,040 weekly downloads. As such, jsonref popularity was classified as popular.
We found that jsonref demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.