
Research
TeamPCP Compromises Telnyx Python SDK to Deliver Credential-Stealing Malware
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.
@toruslabs/session-manager
Advanced tools
This package supports web SDK session flows with two modules:
npm install @toruslabs/session-manager
StorageManager is the legacy encrypted metadata session flow. It creates, authorizes, updates, and invalidates server-backed sessions using a hex session ID.
import { StorageManager } from "@toruslabs/session-manager";
const storage = new StorageManager({
sessionId: StorageManager.generateRandomSessionKey(),
sessionNamespace: "my-app",
});
await storage.createSession({ userId: "123" });
const sessionData = await storage.authorizeSession();
AuthSessionManager handles the full lifecycle of access tokens, refresh tokens, and session data. It stores tokens in configurable storage backends, refreshes them automatically, and deduplicates concurrent refresh calls -- including across browser tabs via the Web Locks API.
import { AuthSessionManager, HttpClient } from "@toruslabs/session-manager";
const session = new AuthSessionManager({
apiClientConfig: {
baseURL: "https://auth.example.com",
// optional: override default endpoints
sessionsEndpoint: "/v1/auth/session",
logoutEndpoint: "/v1/auth/logout",
},
});
After login (e.g. from an auth iframe postMessage), store the full token set:
await session.setTokens({
session_id: "...",
access_token: "...",
refresh_token: "...",
id_token: "...",
});
On page load, call authorize() to refresh tokens and retrieve the encrypted session data:
const sessionData = await session.authorize();
if (sessionData) {
// Session restored -- sessionData contains the decrypted payload
console.log(session.isAuthenticated()); // true
} else {
// No valid session -- redirect to login
}
const accessToken = await session.getAccessToken();
const refreshToken = await session.getRefreshToken();
const idToken = await session.getIdToken();
const sessionId = await session.getSessionId();
Calls the logout endpoint with the current tokens, then clears all stored data:
await session.logout();
By default, tokens are stored in localStorage (access token, session ID, ID token) and cookies (refresh token). You can override any or all of these:
import {
AuthSessionManager,
MemoryStorage,
SessionStorageAdapter,
CookieStorage,
} from "@toruslabs/session-manager";
const session = new AuthSessionManager({
apiClientConfig: { baseURL: "https://auth.example.com" },
storage: {
accessToken: new SessionStorageAdapter(),
refreshToken: new CookieStorage({ secure: true, sameSite: "Lax" }),
sessionId: new MemoryStorage(),
// idToken falls back to localStorage
},
storageKeyPrefix: "myapp", // default: "w3a"
});
You can also implement the IStorageAdapter interface for custom backends (e.g. IndexedDB, a remote store):
import type { IStorageAdapter } from "@toruslabs/session-manager";
class IndexedDBStorage implements IStorageAdapter {
async get(key: string): Promise<string | null> { /* ... */ }
async set(key: string, value: string): Promise<void> { /* ... */ }
async remove(key: string): Promise<void> { /* ... */ }
}
If you manage access tokens externally (e.g. from a parent SDK), provide a callback instead of relying on stored tokens:
const session = new AuthSessionManager({
apiClientConfig: { baseURL: "https://auth.example.com" },
accessTokenProvider: async () => {
return await parentSdk.getAccessToken();
},
});
HttpClient wraps @toruslabs/http-helpers with automatic authorization and transparent 401 retry. It pairs with AuthSessionManager to attach Bearer tokens and refresh them when they expire.
import { AuthSessionManager, HttpClient } from "@toruslabs/session-manager";
const session = new AuthSessionManager({
apiClientConfig: { baseURL: "https://auth.example.com" },
});
const http = new HttpClient(session);
Pass authenticated: true to attach the access token and enable automatic 401 retry:
// GET
const users = await http.get<User[]>("https://api.example.com/users", {
authenticated: true,
});
// POST
const newUser = await http.post<User>(
"https://api.example.com/users",
{ name: "Alice" },
{ authenticated: true }
);
// PUT, PATCH, DELETE work the same way
await http.put("https://api.example.com/users/1", data, { authenticated: true });
await http.patch("https://api.example.com/users/1", data, { authenticated: true });
await http.delete("https://api.example.com/users/1", {}, { authenticated: true });
Omit authenticated (or set it to false) for public endpoints -- no token is attached and 401s are not retried:
const health = await http.get("https://api.example.com/health");
When an authenticated request receives a 401:
HttpClient triggers a token refresh via session.handleUnauthorized().const result = await http.get("https://api.example.com/resource", {
authenticated: true,
headers: { "X-Custom-Header": "value" },
timeout: 5000,
useAPIKey: true,
});
git clone https://github.com/torusresearch/session-manager-web.git
cd session-manager-web
npm i
Each sub package is distributed in 2 formats:
lib.esm build dist/lib.esm/index.js in es6 formatlib.cjs build dist/lib.cjs/index.js in es5 formatBy default, the appropriate format is used for your specified usecase. You can use a different format (if you know what you're doing) by referencing the correct file.
The cjs build is not polyfilled with core-js. It is up to the user to polyfill based on the browserlist they target.
Ensure you have a Node.JS development environment setup:
npm run build
@babel/runtimeFAQs
session manager web
The npm package @toruslabs/session-manager receives a total of 18,769 weekly downloads. As such, @toruslabs/session-manager popularity was classified as popular.
We found that @toruslabs/session-manager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 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
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.

Security News
/Research
Widespread GitHub phishing campaign uses fake Visual Studio Code security alerts in Discussions to trick developers into visiting malicious website.