Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
express-session-cosmosdb
Advanced tools
This is yet another implementation of an Express session provider, this one targeting Azure Cosmos DB.
This is yet another implementation of an Express session provider, this one targeting Azure Cosmos DB.
While there were a previous generation of providers created for documentdb, or the older Cosmos libraries, this targets the 2020+-era Cosmos SDK and uses TypeScript.
This library is repackaged from the open source GitHub Management Portal used at Microsoft that I created as part of my day job. See also: https://github.com/microsoft/opensource-portal/blob/develop/lib/cosmosSession/index.ts
I am unofficially packaging up this for independent use in personal projects for the time being, since it's such a basic library, and publishing into my own scoped NPM package for now.
While you'll want to review the pricing details for Cosmos, the most important capability used for session storage is time-to-live / TTL configuration. By default, Cosmos containers have TTL turned off.
When creating or configuring a new container:
While using Express, you simply initialize a new instance of the CosmosSessionStore
object with
a set of properties, and your Cosmos DB will be used for storing the session.
To protect keys, this sample code assumes you are using the npm dotnev
and .env
files.
require('dotenv').config(); // load .env keys into process environment variables
import express from 'express';
import session from 'express-session';
import CosmosSessionStore from 'express-session-cosmosdb';
// ... standard Express middleware ...
const store = new CosmosSessionStore({
endpoint: process.env.COSMOS_SESSION_ENDPOINT,
database: process.env.COSMOS_SESSION_DATABASE,
collection: process.env.COSMOS_SESSION_CONTAINER,
key: process.env.COSMOS_SESSION_KEY,
});
const sess = {
store,
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
path: '/',
httpOnly: true,
secure: false,
},
}
if (app.get('env') === 'production') {
// IF using a load balancer in Azure - beware: app.set('trust proxy', 1) // trust first proxy
sess.cookie.secure = true // serve secure cookies
}
app.use(session(sess))
// ... continue standard Express middleware ...
The debug
module is used to allow for sharing more verbose information at runtime. If
you set the environment variable DEBUG
to include express-session-cosmosdb
or *
,
initialiation information will be shown.
Helpful debug information includes detailed errors during attempted Cosmos database and container initialization, as well as diagnostics around time-to-life settings and defaults.
node DEBUG=express-session-cosmodb ./bin/www
The required options taken when constructing the CosmosSessionStore
conforming to the interface ICosmosSessionProviderOptions
are:
https://espresso.documents.azure.com:443/
Optional but strongly encouraged:
Optional other parameters:
true
to create the database if it does not exist. This could have billing implications.true
to create the collection if it does not exist. This could have billing implications. The collection also will not have a TTL default or TTL support enabled.true
to skip runtime validation that the database existstrue
to skip runtime validation that the collection existsThis project was originally created as part of the opensource-portal
project at
Microsoft. This is a fork of the ./lib/cosmosSession/
folder, and maintains the
Microsoft copyright and MIT license.
Contributors to this project may be asked to sign the Microsoft CLA.
FAQs
This is yet another implementation of an Express session provider, this one targeting Azure Cosmos DB.
We found that express-session-cosmosdb 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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.