open_basedir enhancement, runtime tightening
| From: | Sara Golemon | Date: | Thu, 12 Oct 2006 19:53:46 +0000 |
| Subject: | open_basedir enhancement, runtime tightening | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-26040@lists.php.net to get a copy of this message | ||
The attached patch changes open_basedir from PHP_INI_SYSTEM to PHP_INI_ALL.
Wait now... let me finish.
It introduces a custom INI modification handler for open_basedir which
allows the option to be set during Startup and Shutdown (PHP_INI_SYSTEM
contexts) normally, then for other contexts (Activate/Deactivate {PERDIR}
and Runtime) it checks the inbound settings against the current value and
applies some logic:
If open_basedir hasn't been set yet: It allows any new setting to be
applied (unrestrictive to restrictive)
If open_basedir is set, then it checks to see if each component of the new
setting would be allowable under the rules of the old setting, if they're
all good, it allows it. If any component makes the basedir check less
restrictive, it fails (diallows) the change. (less-restrictive to
more-restrictive).
The advantage of doing this is that package authors and/or users of shared
hosting who may not have access to making their settings more restrictive
can avoid most simple FS inspection attacks caused by buggy script code by
adding a single ini_set(basedir(__FILE__)); to the top of their script or
setting it with an .htaccess directive.
Note that it doesn't do a thing to avoid code inejction attacks as such an
attacker could issue ini_restore("open_basedir"); and have the same access
to the FS as they would without this patch. I'll grant you it's not a
panacea, and it may be more harmful than good by making people think that
tightening up open_basedir is enough, but it's something.
Talk amongst y'selves....
-Sara
begin 666 open_basedir.txt
M26YD97@Z(&UA:6XO;6%I;BYC"CT]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]
M/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T*4D-3
M(&9I;&4Z("]R97!O<VET;W)Y+W!H<"US<F,O;6%I;B]M86EN+F,L=@IR971R
M:65V:6YG(')E=FES:6]N(#$N-S T"F1I9F8@+74@+7 @+7(Q+C<P-"!M86EN
M+F,*+2TM(&UA:6XO;6%I;BYC"3,@3V-T(#(P,#8@,38Z,C@Z,#(@+3 P,# )
M,2XW,#0**RLK(&UA:6XO;6%I;BYC"3$R($]C="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-T:79A=&EO;B]R=6YT:6UE+V1E86-T:79A=&EO
M;B J+PHK4$A005!)(%I%3D1?24Y)7TU(*$]N57!D871E0F%S941I<BD**WL*
M*PEC:&%R("HJ<"P@*G!A=&AB=68L("IP='(L("IE;F0["BLC:69N9&5F(%I4
M4PHK"6-H87(@*F)A<V4@/2 H8VAA<B J*2!M:%]A<F<R.PHK(V5L<V4**PEC
M:&%R("IB87-E(#T@*&-H87(@*BD@='-?<F5S;W5R8V4H*B@H:6YT("HI(&UH
M7V%R9S(I*3L**R-E;F1I9@HK"BL)<" ]("AC:&%R("HJ*2 H8F%S92LH<VEZ
M95]T*2!M:%]A<F<Q*3L**PHK"6EF("AS=&%G92 ]/2!02%!?24Y)7U-404=%
M7U-405)455 @?'P@<W1A9V4@/3T@4$A07TE.25]35$%'15]32%541$]73BD@
M>PHK"0DO*B!792=R92!I;B!A(%!(4%])3DE?4UE35$5-(&-O;G1E>'0L(&YO
M(')E<W1R:6-T:6]N<R J+PHK"0DJ<" ](&YE=U]V86QU93L**PD)<F5T=7)N
M(%-50T-%4U,["BL)?0HK"BL@(" @(" @( HK"2\J($5L<V5W:7-E+"!W92=R
M92!I;B!R=6YT:6UE("HO"BL):68@*"$J<"!\?"
A*BIP*2!["BL)"2\J(&]P
M96Y?8F%S961I<B!N;W0@<V5T('EE="P@9V\@86AE860@86YD(&=I=F4@:70@
M82!V86QU92 J+PHK"0DJ<" ](&YE=U]V86QU93L**PD)<F5T=7)N(%-50T-%
M4U,["BL)?0HK"BL)+RH@4VAO<G1C=70Z(%=H96X@=V4@:&%V92!A(&]P96Y?
M8F%S961I<B!A;F0@<V]M96]N92!T<FEE<R!T;R!U;G-E="P@=V4@:VYO=R!I
M="=L;"!F86EL("HO"BL):68@*"%N97=?=F%L=64@?'P@(2IN97=?=F%L=64I
M('L**PD)<F5T=7)N($9!24Q54D4["BL)?0HK"BL)+RH@27,@=&AE('!R;W!O
M<V5D(&]P96Y?8F%S961I<B!A="!L96%S="!A<R!R97-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