fix(plugins): close the 4 PARTIAL findings + regressions from the fix-verify pass

A second adversarial pass over the first remediation found four findings only
partially closed and five issues the fixes themselves introduced. This closes
them:

Partial → closed
- re-consent gate keyed on `granted.length > 0`, so a plugin first activated with
  ZERO permissions (granted '[]') was treated as never-consented and a later
  widening was granted silently. Now discovery marks a never-consented plugin with
  granted_permissions '' and activate() gates on "ever consented" (any non-empty
  string, including '[]').
- db:own DoS: block WITH RECURSIVE outright (the one construct that spins the
  synchronous host unboundedly regardless of the size/row caps, via query OR exec).
- dgram: also wrap `new dgram.Socket(...)` (bypassed createSocket) to inject the
  IP-vetting lookup, and lock createSocket/Socket.
- frame self-navigation: documented as a bounded best-effort mitigation (inherent
  to sandboxed iframes; exposure is the plugin's own routes + already-held context,
  never the httpOnly cookie).

Regressions introduced by the first pass → fixed
- proxy: only real redirects (301/302/303/307/308) are gated, to a RELATIVE in-app
  Location (supports OAuth-callback bounce, blocks open redirect); 300/304 pass
  through; attachment only on non-redirects.
- supervisor: measure RSS via /proc/<pid>/status VmRSS (page-size independent);
  activation-timeout awaits kill() before disposing the db handle.
- manifest HOST_RE: allow single-label hosts (self-hoster sibling services) while
  keeping wildcards multi-label; mirrored in the SDK + frame CSP filter.

Regression tests added (re-consent incl. the '[]' case, WITH RECURSIVE + row cap,
single-label host). 236 plugin tests + 24 SDK tests green.
This commit is contained in:
Maurice
2026-07-04 19:03:06 +02:00
committed by Maurice
parent 64136484ee
commit b16a7d7b77
13 changed files with 103 additions and 33 deletions
@@ -278,14 +278,20 @@ function installEgressGuard(egress: string[]): void {
// A dgram HOSTNAME target is resolved via the socket's `lookup` before the packet
// is sent; force the IP-vetting guardedLookup so a declared name that resolves to
// a private/metadata address is refused (the TCP path's rebind backstop, for UDP).
const dgramApi = dgram as unknown as { createSocket: (...a: unknown[]) => unknown };
const injectLookup = (arg: unknown): { type?: unknown; lookup: unknown } =>
typeof arg === 'string' ? { type: arg, lookup: guardedLookup } : { ...(arg as object), lookup: guardedLookup };
const dgramApi = dgram as unknown as { createSocket: (...a: unknown[]) => unknown; Socket: new (o?: unknown, cb?: unknown) => unknown };
const realCreateSocket = dgramApi.createSocket;
dgramApi.createSocket = function (this: unknown, ...args: unknown[]): unknown {
const first = args[0];
if (first && typeof first === 'object') (first as { lookup?: unknown }).lookup = guardedLookup;
else if (typeof first === 'string') args[0] = { type: first, lookup: guardedLookup };
args[0] = injectLookup(args[0]);
return realCreateSocket.apply(this, args);
};
// Also cover `new dgram.Socket(...)`, which bypasses createSocket entirely.
const RealDgramSocket = dgramApi.Socket;
const GuardedDgramSocket = function (options?: unknown, cb?: unknown): unknown {
return new RealDgramSocket(injectLookup(options), cb);
} as unknown as new (o?: unknown, cb?: unknown) => unknown;
(GuardedDgramSocket as unknown as { prototype: unknown }).prototype = RealDgramSocket.prototype;
// Lock the wrapped choke points so a plugin can't restore the originals.
const lock = (obj: object, key: string, value: unknown) => {
@@ -294,6 +300,8 @@ function installEgressGuard(egress: string[]): void {
lock(proto, 'connect', proto.connect);
lock(dgramProto, 'send', dgramProto.send);
lock(dgramProto, 'connect', dgramProto.connect);
lock(dgramApi as unknown as object, 'createSocket', dgramApi.createSocket);
lock(dgramApi as unknown as object, 'Socket', GuardedDgramSocket);
// Gate the dns resolver family: a forward lookup for an undeclared name is a
// DNS-tunnel exfiltration channel even when no socket is ever opened. The name