-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
allow user strings to be parsed with or without compile-caching #30603
base: master
Are you sure you want to change the base?
Conversation
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
$canUseEvalResourceType = !function_exists('smarty_function_eval') | ||
&& (!defined('SMARTY_DIR') | ||
|| !file_exists(SMARTY_DIR . '/plugins/function.eval.php')); | ||
if (!$useCache && $canUseEvalResourceType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my only concern here is the windows element here @demeritcowboy do you have thoughts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something else seems to have changed since 5.69. Let me get back to you...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, this is a very simple refactoring. The function parseOneOffStringThroughSmarty()
should work exactly as before. So any problems with Windows won't have changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the old function might be unchanged but the question is about the new function/usecache=true. It will try to use string:
, and this is where the problem is (was). I'm in and out today but I'd like to (a) determine if there is still a problem, (b) understand what changed elsewhere, and (c) remember what (c) was.
Soooo, it was actually the fact that we were still registering our own string resource that made it appear that smarty3 couldn't handle There may be other reasons to want eval, like to avoid caching sensitive info, but I'm not sure how you would know when and when not to do that here. In the discussion that prompted this PR, assuming we would change this now back to prefer string, would you know when the info is sensitive so you could tell it NOT to cache it? Or alternatively, would you know when it's NOT sensitive? Boring tech details of why the registration matters regarding the filename:
Separate, we may want to revisit #27583 (which is where the string issues first came up and has since been updated to avoid that, but which have a different playing field now). |
Overview
Best practice as of the Civi 5.75 security release is to use functions like
CRM_Utils_String::parseOneOffStringThroughSmarty()
, which wraps Smarty in a security layer, rather than callingCRM_Core_Smarty::singleton()->fetch()
, which is less secure. This PR provides another function,CRM_Utils_String::parseUserStringThroughSmarty()
, which uses the security layer and doesn't disable caching. Based on discussion on MM.Before
If you wanted to parse a user-supplied string in a secure way, it would have to be compiled anew each time.
After
You can parse a user-supplied string in a secure way, and take advantage of Smarty's compiled-template caching if you want.
Comments
I'm not married to the function names here. Any ideas on how to make them clearer and shorter?