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

Fix bypassing function and class restrictions #2

Merged
merged 9 commits into from
Feb 8, 2024

Conversation

antman3351
Copy link
Contributor

Hey,
The sandbox can be bypassed to call any function/class like this:

Function / Class bypass by aliasing

<?php

use function \exec as intval;

intval( 'ls -l' );

Function bypass by declaring a function with the same name

<?php

namespace foobar;

function exec() {
    return 1;
}

return \exec( 'ls' );

…ion in namespace

Added option to restrict creating functions and constants in global namespace
Added option to restrict namespace
@antman3351
Copy link
Contributor Author

I probably should of created a new branch...
because in the mean time I've added the option to restrict creating functions and constants in the global namespace and also restrict the namespace ( if used ).
I also added some more unsafe tests to prevent future regressions

@antman3351
Copy link
Contributor Author

Found another way to bypass function restrictions 😅

<?php

$a = [ 1 ];
// Change argument order
return array_walk( /*array*/ array: $a, /*callback*/ arg: 'intval', /*arg*/ callback: 'var_dump' );

I've added a check for the arguments name in SecurityManager->getArgumentAt()

@chriskapp
Copy link
Member

@antman3351 thanks for this great PR 🚀

src/SecurityManager.php Outdated Show resolved Hide resolved
tests/PHPTestCase.php Outdated Show resolved Hide resolved
src/Printer.php Outdated Show resolved Hide resolved
…erties

Removed extra space after parameter in Printer call to defineFunction method
@antman3351 antman3351 requested a review from chriskapp February 6, 2024 07:45
@antman3351
Copy link
Contributor Author

Hi,
let me know if there's any other changes that need doing 😎

Thanks,
Antonio

Added Advanced configuration (SecurityManagerConfiguration) , requirements and installation to README.md
@chriskapp
Copy link
Member

Hi @antman3351 could you fix the last Psalm issue, then I can merge the PR, I can then also tag a new 0.4 version

@antman3351
Copy link
Contributor Author

Not sure if github notifies when I make a new commit.
I fixed the Psalm error ( I think 😅 )

@chriskapp chriskapp merged commit a52657a into apioo:master Feb 8, 2024
3 checks passed
@chriskapp
Copy link
Member

@antman3351 thanks, I have just merged the PR

@antman3351
Copy link
Contributor Author

Hi, can you add a new tag so composer can see the version

Thanks!
Antonio

@chriskapp
Copy link
Member

Yes, I have just released https://github.com/apioo/psx-sandbox/releases/tag/v0.4.0

@antman3351
Copy link
Contributor Author

Hi, I think something went wrong, the release doesn't contain the merged code

@chriskapp
Copy link
Member

@antman3351 ok, sorry indeed my bad, just tagged a new version which should contain all changes

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

Successfully merging this pull request may close these issues.

2 participants