mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
Integrates two community contributions into release/v3.8.8 with security hardening and conflict resolution. - **Plugins framework** (#2913 — thanks @oyi77): hooks + registry unification, plugin SDK (`definePlugin`), worker-thread sandbox, per-plugin hook rate limiting, SHA-256 integrity verification, semver-gated upgrade, and execution analytics. Plugin routes are loopback-only (`isLocalOnlyPath`); `child_process` exec is opt-in via `OMNIROUTE_PLUGINS_ALLOW_EXEC` (default off). - **API key option: disable non-published models** (#3017 — thanks @androw): a per-key flag restricting the key to discovered public models (combos / `auto/*` / `qtSd/*` routing still allowed). Hardening applied during integration: migration renumber (089/090/091), `/api/plugins` LOCAL_ONLY route-guard classification (closes the plugin-RCE vector), atomic install/upgrade with path containment, `O_EXCL` tmp-file creation (TOCTOU), rate-limit-map eviction, `validatePluginConfig` on configure, `buildErrorBody` on all plugin error paths. 246/246 tests; typecheck / cycles / docs-sync clean. Co-authored-by: oyi77 <14921983+oyi77@users.noreply.github.com> Co-authored-by: Nicolas Lorin <androw95220@gmail.com>
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
/**
|
|
* Plugin logger — per-plugin log isolation.
|
|
*
|
|
* Writes JSON log entries to <pluginDir>/<name>/plugin.log.
|
|
*
|
|
* @module plugins/logger
|
|
*/
|
|
|
|
import { appendFileSync, mkdirSync } from "fs";
|
|
import { join, dirname } from "path";
|
|
|
|
export class PluginLogger {
|
|
private logPath: string;
|
|
|
|
constructor(pluginName: string, pluginDir: string) {
|
|
this.logPath = join(pluginDir, pluginName, "plugin.log");
|
|
}
|
|
|
|
private write(level: string, message: string, data?: unknown): void {
|
|
const entry = JSON.stringify({
|
|
timestamp: new Date().toISOString(),
|
|
level,
|
|
message,
|
|
...(data !== undefined ? { data } : {}),
|
|
});
|
|
|
|
try {
|
|
mkdirSync(dirname(this.logPath), { recursive: true });
|
|
appendFileSync(this.logPath, entry + "\n", "utf-8");
|
|
} catch {
|
|
// Silent fail — don't crash plugin over logging
|
|
}
|
|
}
|
|
|
|
info(message: string, data?: unknown): void {
|
|
this.write("INFO", message, data);
|
|
}
|
|
|
|
error(message: string, data?: unknown): void {
|
|
this.write("ERROR", message, data);
|
|
}
|
|
|
|
warn(message: string, data?: unknown): void {
|
|
this.write("WARN", message, data);
|
|
}
|
|
|
|
debug(message: string, data?: unknown): void {
|
|
this.write("DEBUG", message, data);
|
|
}
|
|
}
|