
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
@node-wot/binding-http
Advanced tools
In the following examples it is shown how to use the HTTP binding of node-wot.
npm install @node-wot/core
npm install @node-wot/binding-http
The client example tries to connect to a TestThing via HTTP and reads a property string
. The ThingDescription is located under the follwing uri http://plugfest.thingweb.io:8083/TestThing.
node example-client.js
// example-client.js
Servient = require("@node-wot/core").Servient
HttpClientFactory = require("@node-wot/binding-http").HttpClientFactory
Helpers = require("@node-wot/core").Helpers
// create Servient and add HTTP binding
let servient = new Servient();
servient.addClientFactory(new HttpClientFactory(null));
let wotHelper = new Helpers(servient);
wotHelper.fetch("http://plugfest.thingweb.io:8083/TestThing").then(async (td) => {
// using await for serial execution (note 'async' in then() of fetch())
try {
servient.start().then((WoT) => {
WoT.consume(td).then((thing) => {
// read a property "string" and print the value
thing.readProperty("string").then((s) => {
console.log(s);
});
});
});
} catch (err) {
console.error("Script error:", err);
}
}).catch((err) => { console.error("Fetch error:", err); });
The server example produces a thing that allows for setting a property count
. The thing is reachable through HTTP. Additional additional handlers could be added.
node example-server.js
// example-server.js
Servient = require("@node-wot/core").Servient
HttpServer = require("@node-wot/binding-http").HttpServer
Helpers = require("@node-wot/core").Helpers
// create Servient add HTTP binding with port configuration
let servient = new Servient();
servient.addServer(new HttpServer({
port: 8081 // (default 8080)
}));
servient.start().then((WoT) => {
WoT.produce({
"@context": "https://www.w3.org/2019/wot/td/v1",
title: "MyCounter",
properties: {
count: {
type: "integer"
}
}
}).then((thing) => {
console.log("Produced " + thing.getThingDescription().title);
thing.writeProperty("count", 0)
thing.expose().then(() => {
console.info(thing.getThingDescription().title + " ready");
console.info("TD : " + JSON.stringify(thing.getThingDescription()));
thing.readProperty("count").then((c) => {
console.log("cound is " + c);
});
});
});
});
The secure server example shows how to add credentials and how to setup HTTPS.
node example-server-secure.js
// example-server-secure.js
Servient = require("@node-wot/core").Servient
HttpServer = require("@node-wot/binding-http").HttpServer
Helpers = require("@node-wot/core").Helpers
// create secure Servient with username & password credentials
let servient = new Servient();
servient.addCredentials({
"urn:dev:wot:org:eclipse:thingweb:my-example-secure": {
username: "node-wot",
password: "hello"
// token: "1/mZ1edKKACtPAb7zGlwSzvs72PvhAbGmB8K1ZrGxpcNM"
}
});
let httpConfig = {
allowSelfSigned: true, // client configuration
serverKey: "privatekey.pem",
serverCert: "certificate.pem",
security: {
scheme: "basic" // (username & password)
}};
// add HTTPS binding with configuration
servient.addServer(new HttpServer(httpConfig));
servient.start().then((WoT) => {
WoT.produce({
"@context": "https://www.w3.org/2019/wot/td/v1",
id: "urn:dev:wot:org:eclipse:thingweb:my-example-secure",
title: "MyCounter",
properties: {
count: {
type: "integer"
}
}
}).then((thing) => {
console.log("Produced " + thing.getThingDescription().title);
thing.writeProperty("count", 0)
thing.expose().then(() => {
console.info(thing.getThingDescription().title + " ready");
console.info("TD : " + JSON.stringify(thing.getThingDescription()));
thing.readProperty("count").then((c) => {
console.log("cound is " + c);
});
});
});
});
FAQs
HTTP client & server protocol binding for node-wot
We found that @node-wot/binding-http 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
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.