
Research
npm Malware Targets Telegram Bot Developers with Persistent SSH Backdoors
Malicious npm packages posing as Telegram bot libraries install SSH backdoors and exfiltrate data from Linux developer machines.
ts-request-mediator
Advanced tools
npm install ts-request-mediator reflect-metadata
yarn add ts-request-mediator reflect-metadata
tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
flowchart LR;
requestHandler1-->requestHandler2-->id1{{targetHandler}}-->requestHandler3-->requestHandler4;
Example:
flowchart LR;
AuthorizeUser-->id1{{CreateTodo}}-->LogRequest;
flowchart LR;
useCaseHandler1-->useCaseHandler2-->id1{{targetHandler}}-->useCaseHandler3-->useCaseHandler4;
Example:
flowchart LR;
SetUserContext-->id1{{CreateTodo}}-->DoSmthAfter;
flowchart LR;
serviceHandler1-->serviceHandler2-->id1{{targetHandler}}-->serviceHandler3-->serviceHandler4;
import { IQueryHandler, request, context, transaction, useService, inject } from "ts-request-mediator";
import { by } from "ts-ioc-container";
@transaction
@request("before", [AuthorizeUser])
@request("after", [LogRequest])
@useCase("before", [SetUserContext])
class CreateTodo implements IQueryHandler<CreateTodoQuery, Todo> {
constructor(
@inject(by(ITodoRepositoryKey)) private todoRepository: ITodoRepository,
@inject(context(IUserKey)) private user: IUser,
@inject(useService(INotifyAllUsersKey, { transaction: true })) private notifyAllUsers: INotifyAllUsers
) {
}
@before
validate(query: CreateTodoQuery): void {
PermissionError.assert(this.user.isAdmin, "User has no permission to create a todo");
}
async handle(query: CreateTodoQuery): Promise<Todo> {
const todo = await this.todoRepository.create(query);
return todo;
}
@after
async notify(query: CreateTodoQuery, todo: Todo): Promise<void> {
await this.notifyAllUsers.handle(todo);
}
}
const INotifyAllUsersKey = Symbol("INotifyAllUsers");
interface INotifyAllUsers extends IQueryHandler<Todo, void> {
}
class NotifyAllUsers implements INotifyAllUsers {
constructor(
@inject(by(INotificationServiceKey)) private notificationService: INotificationService
) {
}
async handle(todo: Todo): Promise<void> {
const users = await this.userRepository.findAll();
await this.notificationService.notify(users, `New todo created: ${todo.title}`);
}
}
import { IDependencyContainer } from 'ts-ioc-container';
export class ContainerAdapter implements IDependencyContainer {
constructor(private container: IContainer) {}
createScope(tags: string[]): IDependencyContainer {
return new ContainerAdapter(this.container.createScope(tags));
}
dispose(): void {
this.container.dispose();
}
registerValue(key: string | symbol, value: unknown): void {
this.container.register(fromValue(value).forKey(key).build());
}
resolve<T>(key: constructor<T> | symbol): T {
return this.container.resolve(key);
}
}
const mediator = new RequestMediator(new ContainerAdapter(container));
const todo = await mediator.send(CreateTodo, {title: 'Buy milk', description: '2% fat'});
import { PrismaClient } from '@prisma/client';
import { forKey, Resolveable } from 'ts-ioc-container';
import { ITransactionContextKey, ITransactionContext } from 'ts-request-mediator';
import { perApplication } from '../../core/di';
@perApplication
@forKey(ITransactionContextKey)
export class PrismaTransactionContext implements ITransactionContext {
constructor(public dbClient: PrismaClient = new PrismaClient()) {}
execute<Response>(setContext: (context: ITransactionContext) => Promise<Response>): Promise<Response> {
return this.dbClient.$transaction((transactionClient) =>
setContext(new PrismaTransactionContext(transactionClient as PrismaClient)),
);
}
}
export const prismaClient = (c: Resolveable) =>
l.resolve<PrismaTransactionContext>(ITransactionContextKey).dbClient;
FAQs
Request mediator for server
The npm package ts-request-mediator receives a total of 0 weekly downloads. As such, ts-request-mediator popularity was classified as not popular.
We found that ts-request-mediator demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Malicious npm packages posing as Telegram bot libraries install SSH backdoors and exfiltrate data from Linux developer machines.
Security News
pip, PDM, pip-audit, and the packaging library are already adding support for Python’s new lock file format.
Product
Socket's Go support is now generally available, bringing automatic scanning and deep code analysis to all users with Go projects.