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.
ewd-session
Advanced tools
Rob Tweed rtweed@mgateway.com
24 February 2016, M/Gateway Developments Ltd http://www.mgateway.com
Twitter: @rtweed
Google Group for discussions, support, advice etc: http://groups.google.co.uk/group/enterprise-web-developer-community
This module may be used to provide session management. Sessions make use of the persistent JavaScript objects and fine-grained document database provided by ewd-document-store. For more information on ewd-document-store:
https://github.com/robtweed/ewd-document-store
You'll usually use ewd-session within an ewd-qoper8 worker process. For more informaation on ewd-qoper8:
https://github.com/robtweed/ewd-qoper8
npm install ewd-session
If you are using ewd-session within an ewd-qoper8 worker process, you must first have connected the worker to a database that is supported by ewd-document-store, eg:
Specifically, ewd-session expects the worker process to have instantiated a DocumentStore object, which is what these database-specific modules will have done when invoked within the worker's start
event handler, eg:
this.on('start', function() {
var connectCacheTo = require('ewd-qoper8-cache');
connectCacheTo(this);
// this.documentStore provides access to the DocumentStore object
});
In order to create and use Sessions, you must load the ewd-session module into your ewd-qoper8 worker module:
var sessions = require('ewd-session');
This provides you with the following constructors and methods:
You must first initialise ewd-sessions. This provides it with access to the DocumentStore object, eg:
sessions.init(this.documentStore);
By default, Sessions are maintained in a Document named '%zewdSession'
. You can change this by using the init() function's second argument, eg:
sessions.init(this.documentStore, 'mySessionDocument');
It is important to enable Session Garbage collection, otherwise your Document Store will accumulate expired session data.
If you are using ewd-qoper8, you should start an instance of the Session Garbage collector timer in your worker module. Do this within the worker's on('DocumentStoreStarted') handler:
this.on('DocumentStoreStarted', function() {
sessions.garbageCollector(this);
});
By default, every 5 minutes, this timer will check the Document Store for sessions and delete any expired ones. You can adjust the checking frequency using the 2nd optional argument which specifies the delay time in seconds:
sessions.garbageCollector(this, 1200); // check every 20 minutes
To create a new Session:
var applicationName = 'vista';
var sessionTimeout = 300; // in seconds; defaults to 3600 = 1 hour
var session = sessions.create(application, sessionTimeout);
You'll be returned a Session object which provides access to the underlying DocumentNode storing the session's data.
A Token Object will also have been created. This provides a pointer from the session's unique token to the Session. You don't directly access the Token Object.
Normally you'll send the Session token value (session.token) back to the client / browser. It is used for subsequent, secure access to the Session the next time the user or client requires access to their Session.
You'll normally send a Session token as part of a message to your worker module. In the case of Express HTTP requests, the token will normally be conveyed as the Authorization header value. In WebSocket messages, you can allocate an appropriate message property to hold it.
To access the associated Session, use the authenticate method:
var results = sessions.authenticate(token);
Where token is the value of the Session Token. Results is an object of the structure:
{
error: errorMessage,
session: SessionObject
}
results.session will contain the associated Session object if:
Otherwise results.error will be defined and will be a string value that explains the reason why a Session object could not be returned.
By default, a successful invocation of the sessions.authenticate() method will update the associated Session's expiry time. In certain circumstances you might not want this to happen, for example if you want to log in the user. In such a situation, if the login credentials aren't correct, you'll want to keep the clock ticking in terms of the remaining time you allow before the user can log in.
In such a situation, add true as a third argument:
var results = sessions.authenticate(token, true);
You'll find two examples in the /examples path of this module repository:
/qoper8/initiate
which starts a Session and returns a token. You can then login using a POST request of /qoper8/login
with a payload: {"username": "rob", "password": "secret"}
cache.node
in npm global registy. Read Installation to get more details.npm link cache.node
before running integration tests.Copyright (c) 2016 M/Gateway Developments Ltd,
Reigate, Surrey UK.
All rights reserved.
http://www.mgateway.com
Email: rtweed@mgateway.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
FAQs
Session management using ewd-document-store DocumentNodes
The npm package ewd-session receives a total of 2 weekly downloads. As such, ewd-session popularity was classified as not popular.
We found that ewd-session 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.