2 # Copyright (c) 2021-2024, PostgreSQL Global Development Group
4 # src/pl/plperl/plc_trusted.pl
6 #<<< protect next line from perltidy so perlcritic annotation works
7 package PostgreSQL
::InServer
::safe
; ## no critic (RequireFilenameMatchesPackage)
10 # Load widely useful pragmas into plperl to make them available.
14 # Since these modules are free to compile unsafe opcodes they must
15 # be trusted to now allow any code containing unsafe opcodes to be abused.
16 # That's much harder than it sounds.
18 # Be aware that perl provides a wide variety of ways to subvert
19 # pre-compiled code. For some examples, see this presentation:
20 # http://www.slideshare.net/cdman83/barely-legal-xxx-perl-presentation
22 # If in ANY doubt about a module, or ANY of the modules down the chain of
23 # dependencies it loads, then DO NOT add it to this list.
25 # To check if any of these modules use "unsafe" opcodes you can compile
26 # plperl with the PLPERL_ENABLE_OPMASK_EARLY macro defined. See plperl.c
32 require feature
if $] >= 5.010000;
34 #<<< protect next line from perltidy so perlcritic annotation works
35 package PostgreSQL
::InServer
::WarnEnv
; ## no critic (RequireFilenameMatchesPackage)
41 our @ISA = qw(Tie::StdHash);
43 sub STORE
{ warn "attempted alteration of \$ENV{$_[1]}"; }
44 sub DELETE
{ warn "attempted deletion of \$ENV{$_[1]}"; }
45 sub CLEAR
{ warn "attempted clearance of ENV hash"; }
47 # Remove magic property of %ENV. Changes to this will now not be reflected in
48 # the process environment.
51 # Block %ENV changes from trusted PL/Perl, and warn. We changed %ENV to just a
52 # normal hash, yet the application may be expecting the usual Perl %ENV
53 # magic. Blocking and warning avoids silent application breakage. The user can
54 # untie or otherwise disable this, e.g. if the lost mutation is unimportant
55 # and modifying the code to stop that mutation would be onerous.
56 tie
%main::ENV
, 'PostgreSQL::InServer::WarnEnv', %ENV or die $!;