Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String::_source open_basedir pre-check for urandom #1212

Closed
wants to merge 5 commits into from
Closed

String::_source open_basedir pre-check for urandom #1212

wants to merge 5 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 15, 2015

Requires open_basedir to be unset in order to use /dev/urandom. Prevents "is_readable(): open_basedir restriction in effect. File(/dev/urandom) is not within the allowed path(s)" error. This is the proper way to handle this case instead of silencing is_readable.

Requires open_basedir to be unset in order to use /dev/urandom.  Prevents "is_readable(): open_basedir restriction in effect. File(/dev/urandom) is not within the allowed path(s)" error.  This is the proper way to handle this case instead of silencing is_readable.
@mariuswilms
Copy link
Member

As we generally need tests for changes: do you think it's possible to create one for this case? I currently cannot imagine how, as we'd need to mock open base dir. Might as well create a test that skips if open base dir is not in effect?

@ghost
Copy link
Author

ghost commented Oct 15, 2015

@DavidPersson What I know is that before I made the change, I got a nasty PHP warning and the random string generator was broken, and now it's working. As you said, not possible to do a test case.

You'll have to use your discretion here, this is a special case.

@mariuswilms
Copy link
Member

I absolutely believe this is an issue. As a compromise would you add a test that skips if open base dir is not in effect and sets expectations on generated errors?

$this->assertException('/HMAC strategy requires a secret key./', function() {

$this->skipIf(!MockEncrypt::enabled(), 'The Mcrypt extension is not installed or enabled.');

Thanks!

@nateabele
Copy link
Member

open_basedir is not ini_set()-able, so this would require a fully separate Travis build... 😐

@ghost
Copy link
Author

ghost commented Oct 16, 2015

Have you guys ever heard that story about a hammer factory...

@mariuswilms
Copy link
Member

Then I'd vote for creating the conditionally run test (I've mentioned earlier), but don't create a new travis build. The decision if we may always want to run under the open_basedir restriction (kind of leads up to there), is one I don't want to make now.

@ghost
Copy link
Author

ghost commented Oct 16, 2015

To be clear, I just edit the String test file and add a function to test this case, and then make a pull request?

@mariuswilms
Copy link
Member

Yes and run lithium/console/li3 test lithium/tests/cases/util/StringTest.php to check if the test skips if open_basedir isn't set, and does not skip and is green when it is set.

You can amend this PR with the test. Just push the changes into the same PR branch.

@ghost
Copy link
Author

ghost commented Oct 16, 2015

Done.

@mariuswilms
Copy link
Member

I gave this issue a little bit more thought. Sorry for doing this a bit late - but better late than never ;)

ini_get('open_basedir') != true is not enough, as it would fail even if I put /dev/urandom into the open_basedir.

This would also be the strategy to resolve the problem, if you control the setting. For other environments I suggest we add other sources of randomness before urandom is selected.

This would target lithium\security\Random in 1.1 as per our release policy:
https://github.com/UnionOfRAD/lithium/blob/1.1/security/Random.php
https://github.com/ircmaxell/random_compat/blob/master/lib/random.php#L189-L194

@mariuswilms
Copy link
Member

Checking for open_basedir isn't an option as path checking would get too complex.

For the time being I've added a note, that shows how to workaround the issue.
https://github.com/UnionOfRAD/lithium/blob/1.0/util/String.php#L118-L120

Mid-term, I'm thinking about adding more sources for randomness, or make Random adaptable.

@mariuswilms
Copy link
Member

Refs #1216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants