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

Snuffleupagus 0.10.0 when loaded via Apache only applies ruleset when it has no comments #477

Open
demonfoo opened this issue Jan 3, 2024 · 9 comments

Comments

@demonfoo
Copy link

demonfoo commented Jan 3, 2024

I'm experimenting with using Snuffleupagus to further secure our PHP runtime environments. With 0.9.0, the ruleset I'd worked up applies and catches denied function calls, and with 0.10.0, when run via the PHP CLI it does as well.

However, I discovered that with 0.10.0, the same ruleset does... literally nothing with PHP loaded into Apache. I removed everything but a single drop() directive and it worked, then I tried re-adding some other material and it again didn't work.

A bit more experimentation revealed that, when I removed all the inline comments, the ruleset then worked. I'm not sure why it's only when loaded via Apache, but that is definitely the case; after removing comments, the function drop() directives work as expected.

Please let me know what further information I can provide. Thanks.

@jvoisin
Copy link
Owner

jvoisin commented Jan 3, 2024

This sounds both equally wrong and horrible.

The configuration parser was a bit simplified in cee5535, so odds are that if something is wrong, it should be in it. However, Snuffleupagus doesn't care whether it's running under Apache or whatever else.

Do you have some funky sandboxing going on with Apache that might prevent the php process from reading the rules? If it's the case, Snuffleupagus should complain about it in its logs and in a phpinfo() call.

You can use the SP_DUMP_CONFIG environment variable to dump the whole thing.

@demonfoo
Copy link
Author

demonfoo commented Jan 3, 2024

We are using chroot() with Apache via the ChrootDir directive, but I hardlinked the config file inside the chroot() environment at the same path. I also did an strace of Apache running, and I only saw the parent process reading the rules file the one time, there were no attempts in the child processes to walk /etc/php.d/ and re-read the config file. Also, the fact that the same config directives are now working so long as the comments are removed would seem to point to something with the parsing, though obviously I can't say what.

@demonfoo
Copy link
Author

demonfoo commented Jan 3, 2024

Also, it did not complain about any parsing issues in either the Apache log file or in phpinfo() output; I'd been loading a bit of PHP calling phpinfo() (as it's one of the functions I meant to block), and it showed the php.ini config directives and no complaints about parsing issues. It just seems that anything past a comment line just got ignored, like it didn't see the newlines or something?

@jvoisin
Copy link
Owner

jvoisin commented Jan 3, 2024

Also, the fact that the same config directives are now working so long as the comments are removed would seem to point to something with the parsing, though obviously I can't say what.

Indeed, but you said that it's working in the cli, which is super-duper-confusing :/

Are you sure you're running the same versions in the cli and in apache?

@demonfoo
Copy link
Author

demonfoo commented Jan 3, 2024

Yes, there's only a single snuffleupagus.so on the machines in question. It's installed via the Remi RPMs, though I did notice they don't depend on re2c (I tried rebuilding them via rpmbuild), so it apparently doesn't regenerate the generated .c file? I don't know if that's a problem or not.

@jvoisin
Copy link
Owner

jvoisin commented Jan 3, 2024

@remicollet might know :)

Anyway, the plot thickens! I'll try to play with comments in configuration files maybe tomorrow, more likely this weekend.

@demonfoo
Copy link
Author

demonfoo commented Jan 3, 2024

FWIW, I tried to use my rebuilt RPM with a copy of the config with the comments restored, and it did the same thing (I built the package with re2c installed on the host). So that doesn't seem to make a difference.

jvoisin added a commit that referenced this issue Jan 9, 2024
This should help diagnose #477
@jvoisin
Copy link
Owner

jvoisin commented Jan 12, 2024

I didn't manage to reproduce the issue on my end :/

@nickchomey
Copy link

Can I suggest dumping put the phpinfo()/php -i for cli and for Apache? It's entirely possible they're using different ini files

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

No branches or pull requests

3 participants