Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php: open_basedir and /dev/urandom

Calling the Pear Mail class in some instances automatically attempts to read /dev/urandom, however access is restricted due to an open_basedir setting. Is it safe to add /dev to open_basedir? Or is there a better way around this?

like image 369
Jay Avatar asked Mar 21 '26 21:03

Jay


2 Answers

Do you trust everyone who will be writing PHP for your server? If not, then adding /dev to open_basedir is probably a bad idea.

As for why, the only reason I can think of for why random numbers would be needed is if you are trying to start an SSL connection with an SMTP server. Are you trying to use SSL?

like image 183
Andru Luvisi Avatar answered Mar 23 '26 12:03

Andru Luvisi


Empirical testing (in PHP 7.1.18) shows you can add /dev/urandom to open_basedir to allow access to only that ‘device’ (provided there is no trailing slash, i.e. not /dev/urandom/). More generally, you can allow access to specific files within a directory without allowing access to the directory itself, other files within it, or subdirectories.

I don't know if this (apparently undocumented) feature was present in PHP at the time the question was asked.

like image 41
Jake Avatar answered Mar 23 '26 12:03

Jake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!