Re: sandboxing untrusted code

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Noah Misch <noah(at)leadboat(dot)com>
Subject: Re: sandboxing untrusted code
Date: 2026-04-24 00:47:11
Message-ID: 16be8e08593e33c1d49850d832b85072fcc12658.camel@j-davis.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 2023-08-31 at 11:25 -0400, Robert Haas wrote:
> And that brings me to another point, which is that we might think of
> sandboxing some operations, either by default or unconditionally, for
> reasons other than trust or the lack of it. There's a lot of things
> that you COULD do in an index expression that you really SHOULD NOT
> do. As mentioned, even reading a table is pretty sketchy, but should
> a
> function called from an index expression ever be allowed to execute
> DDL? Is it reasonable if such a function wants to execute CREATE
> TABLE? Even a temporary table is dubious, and a non-temporary table
> is
> really dubious. What if such a function wants to ALTER ROLE ...
> SUPERUSER? I think that's bonkers and should almost certainly be
> categorically denied. Probably someone is trying to hack something,
> and even if they aren't, it's still nuts. So I would argue that in a
> context like an index expression, some amount of sandboxing -- not
> necessarily corresponding to either of the levels described above --
> is probably a good idea, not based on the relationship between
> whatever users are involved, but based rather on the context. There's
> room for a lot of bikeshedding here and I don't think this kind of
> thing is necessarily the top priority, but I think it's worth
> thinking
> about.

"sandboxing... based rather on context" is worth discussing further, in
my opinion.

Imagine two criteria: (a) how hard is it to avoid accidentally invoking
the expression; and (b) how restrictive a sandbox around the expression
might be before it breaks reasonable use cases.

For instance, index expressions are pretty hard to avoid invoking
accidentally, but a sandbox could be quite restrictive before it really
started breaking index expressions. In contrast, we can't be too
restrictive when evaluating functions-in-views because it would break
too many things, but whether they get executed accidentally can be
controlled with restrict_nonsystem_relation_kind.

Regards,
Jeff Davis

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Lamberson 2026-04-24 01:10:44 Re: [PATCH] Don't call ereport(ERROR) from recovery target GUC assign hooks
Previous Message Greg Lamberson 2026-04-24 00:44:08 Re: Extensible sync handler registration (register_sync_handler)