webssh2-server
Version:
A Websocket to SSH2 gateway using xterm.js, socket.io, ssh2
55 lines (54 loc) • 2.35 kB
TypeScript
import type { Branded } from '../types/branded.js';
/**
* Branded type for keys that have been validated as safe for property access
*/
export type SafeKey = Branded<string, 'SafeKey'>;
/**
* Create a SafeKey from a string that is known to be safe at compile time
* Use this for keys from static mappings or Object.keys/entries
*/
export declare function createSafeKey(key: string): SafeKey;
/**
* Validate that a key exists in a known safe set
* Returns a SafeKey if validation passes, undefined otherwise
*/
export declare function validateKey(key: string, safeKeys: ReadonlySet<string>): SafeKey | undefined;
/**
* Type-safe property getter that requires a SafeKey
* This eliminates the need for eslint-disable security/detect-object-injection
*/
export declare function safeGet<T extends Record<string, unknown>>(obj: T, key: SafeKey): unknown;
/**
* Type-safe property setter that requires a SafeKey
* This eliminates the need for eslint-disable security/detect-object-injection
*/
export declare function safeSet<T extends Record<string, unknown>, V>(obj: T, key: SafeKey, value: V): void;
/**
* Safely access nested properties using a dot-separated path
* All path segments must be from a known safe source
*/
export declare function safeGetNested(obj: Record<string, unknown>, path: readonly SafeKey[]): unknown;
/**
* Safely set nested properties using a path array
* Creates intermediate objects as needed
*/
export declare function safeSetNested(obj: Record<string, unknown>, path: readonly SafeKey[], value: unknown): void;
/**
* Create SafeKeys from Object.entries results
* Since Object.entries only returns the object's own keys, they are safe
*/
export declare function safeEntries<T extends Record<string, unknown>>(obj: T): Array<[SafeKey, unknown]>;
/**
* Create SafeKeys from Object.keys results
* Since Object.keys only returns the object's own keys, they are safe
*/
export declare function safeKeys<T extends Record<string, unknown>>(obj: T): SafeKey[];
/**
* Type guard to check if a value is a record object
*/
export declare function isRecord(value: unknown): value is Record<string, unknown>;
/**
* Create a SafeKey from a path string, splitting on dots
* Only use this with paths from static configuration, not user input
*/
export declare function safePathToKeys(path: string): SafeKey[];