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.
@rdfjs/express-handler
Advanced tools
The @rdfjs/express-handler
middleware provides methods to parse incoming RDF data from request with content like POST
or PUT
requests.
It also provides methods to serialize outgoing RDF data.
The package returns a factory function to create express middlewares.
Adding it to all routes of the app would look like this:
import express from 'express'
import rdfHandler from '@rdfjs/express-handler'
const app = express()
app.use(rdfHandler())
The factory accepts the following options:
factory
: The factory used to create Dataset instances. Default: require('rdf-ext')
formats
: An object with parsers
and serializers
, each given as @rdfjs/sink-map
. Default: require('@rdfjs/formats-common')
defaultMediaType
: If an unknown Content-Type is given, this media type will be used. Default: undefined
baseIriFromRequest
: If true
, will call absolute-url to get the requested IRI and pass as base IRI to the parser.
It can also be a function async (req) => string
which can be used to compute the base IRI for the parser.sendTriples
: If true
, the RDF/JS Quads sent using res.dataset()
or res.quadStream()
are converted to triples (default graph). Default undefined
.Routes following the RDF Handler can access the parsed Quads from the request as a Stream or Dataset.
The req.dataset()
and req.quadStream()
methods can be used for this.
But the methods are only attached if the request contains content in a type supported by one of the parsers.
The logic to access the Quads could look like this:
app.use((req, res) => {
if (!req.dataset) {
return res.status(406).end() // send 406 not acceptable if the content can't be parsed
}
const dataset = await req.dataset()
})
req.dataset()
requires await
as it's an async method.
req.quadStream()
is a sync method.
Both methods accept an options object, which is forwarded to the parser.
The RDF Handler middleware always attaches the res.dataset()
and res.quadStream()
methods.
The methods must be called with the Dataset or Stream, which should be sent.
A second options object can be given, which will be forwarded to the serializer.
Sending a Dataset would look like this:
app.use((req, res) => {
await res.dataset(dataset)
})
Both methods are async and finished once the response was sent.
If you don't know if @rdfjs/express-handler
is used earlier in the application, it's possible to attach it dynamically.
That is useful inside of a middleware where you want to use an application RDF Handler instance and it's options, but fallback to a local instance if there is no RDF Handler earlier in the routes.
The .attach()
function can be used.
await
must be used, as it's an async function.
app.use((req, res) => {
await rdfHandler.attach(req, res)
if (req.dataset) {
const dataset = await req.dataset()
}
await res.dataset(rdf.dataset())
})
FAQs
Handle incoming and outgoing RDF data in Express
We found that @rdfjs/express-handler 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.