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.
@travetto/asset
Advanced tools
Install: @travetto/asset
npm install @travetto/asset
# or
yarn add @travetto/asset
The asset module requires an Streaming to provide functionality for reading and writing streams. You can use any existing providers to serve as your Streaming, or you can roll your own.
Install: provider
npm install @travetto/model-{provider}
# or
yarn add @travetto/model-{provider}
Currently, the following are packages that provide Streaming support:
Code: Configuration Methods
import { InjectableFactory } from '@travetto/di';
import { ModelStreamSupport } from '@travetto/model';
import { AssetModelⲐ, AssetService } from '@travetto/asset';
class SymbolBasedConfiguration {
@InjectableFactory(AssetModelⲐ)
static getAssetModelService(service: ModelStreamSupport) {
return service;
}
}
/* OR */
class FullConfiguration {
@InjectableFactory()
static getAssetService(service: ModelStreamSupport) {
return new AssetService(service);
}
}
Reading of and writing assets uses the AssetService. Below you can see an example dealing with a user's profile image.
Code: User Profile Images
import { ModelCrudSupport } from '@travetto/model';
import { AssetService, Asset } from '@travetto/asset';
import { User } from './user';
export class UserProfileService {
constructor(
public asset: AssetService,
public model: ModelCrudSupport
) { }
async saveProfileImage(userId: string, image: Asset) {
const path = await this.asset.upsert(image);
const user = await this.model.get(User, userId);
user.profileImage = path;
await this.model.update(User, user);
}
async getProfileImage(userId: string) {
const user = await this.model.get(User, userId);
return await this.asset.get(user.profileImage);
}
}
By default, the assets are stored by path, as specified in the Asset object. This is standard, and expected, but some finer control may be desired. In addition to standard naming, the module also supports naming by hash, to prevent duplicate storage of the same files with different hashes. This is generally useful when surfacing a lot of public (within the application) user-generated content.
The underlying contract for a AssetNamingStrategy looks like:
Code: AssetNamingStrategy
export interface AssetNamingStrategy {
readonly prefix: string;
/**
* Produce a path for a given asset
* @param asset Get path from an asset
*/
resolve(asset: StreamMeta): string;
}
By extending this, and making it @Injectable, the naming strategy will become the default for the system.
In addition to reading and writing, you can also retrieve information on the saved asset, including basic information, and additional meta data. The structure of the Asset looks like:
Code: Asset Structure
import { Readable } from 'node:stream';
import { StreamMeta } from '@travetto/model';
/**
* An asset, for storage
*
* @concrete ./internal/types#AssetImpl
*/
export interface Asset extends StreamMeta {
source: Readable | string | Buffer;
localFile?: string;
}
/**
* An asset response
*/
export interface AssetResponse extends StreamMeta {
stream(): Readable;
/**
* Response byte range, inclusive
*/
range?: [start: number, end: number];
}
To get the asset information, you would call:
Code: Fetching Asset Info
import { UserProfileService } from './user-profile';
import { User } from './user';
export class UserProfileTagService extends UserProfileService {
async getImageContentType(userId: string) {
const user = await this.model.get(User, userId);
const info = await this.asset.describe(user.profileImage);
return info.contentType; // Return image content type
}
}
FAQs
Modular library for storing and retrieving binary assets
We found that @travetto/asset 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
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.