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:concatenation prohibition #33612

Closed
wants to merge 2 commits into from
Closed

Conversation

bafbes
Copy link
Contributor

@bafbes bafbes commented Mar 26, 2025

Erroneous concatenation function prohibition in formulas

Unuseful concatenation function prohibition in formulas
@@ -11082,14 +11082,6 @@ function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring = '1'
return '';
}
}
if (preg_match('/[^0-9]+\.[^0-9]+/', $s)) { // We refuse . if not between 2 numbers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this rule ?
Which use cas do you want to solve ?

Copy link
Contributor Author

@bafbes bafbes Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple concatenation expression such as $a.$b is matched by this rule and is rejected. So, it prevents the use of the php concatenation operator in calculated extrafields formulas.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a security feature. concat is used to obfuscated evil instruction.
We want for the moment to keep the possible things available into dol_eval as simple as possible.
So to allow concatenation, can you provide an example of instruction you want to introduce into dol_eval (with value) so we can see how wa can allow concatenation without breaking security?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bafbes,
I needed to have an extrafield to see the date of the last paiement of factures (when partially paid) in list view.
Impossible to do it without database request, and need concatenation of ID with the SQL request.

I've managed to do it with dol_concatdesc :
dol_concatdesc('SELECT datep FROM llx_facture_paiement WHERE f_rowid = ' , $objectoffield->id)

I hope that it will help you.

@eldy it seems to me that dol_eval should not be limited but protected. If an attacker can make dol_eval execute string, it is not preventing concatenation that will prevent anything, am i wrong ? But maybe there are usages that i'm not seeing.
It seems to me that it is as usefull as trying to forbid usage of JOIN inside the $db->sql() function. We need it and if an attacker is allowed to execute sql requests, that is not preventing the JOIN that will enhance security.
But as i've said, you have a far greater view on large-scale use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use an extrafield for contract objects called path in Sellyoursaas module. It is calculated by the formula '/home/jail/home/'.$object->array_options['options_username_os'].'/'.$object->array_options['options_database_db']. This formula is no longer acceptable by this test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the forum, we can find users that are using implode( ' ', array('myString1', 'myString2')) to circumvent this dot restriction.

Copy link
Member

@eldy eldy Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bafbes
I pushed a better fix.
The concate is disallowed now only if MAIN_DISALLOW_STRING_OBFUSCATION_IN_DOL_EVAL is set so we can restore the same level of security if we need.

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label Mar 26, 2025
@eldy eldy closed this in 3edadbd Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Some questions or discussions are opened and wait answers of author or other people to be processed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants