Skip to content

Various fixes for PHP 8 compatibility#1483

Merged
glensc merged 6 commits intoeventum:masterfrom
inguin:php8-fixes
Jan 17, 2023
Merged

Various fixes for PHP 8 compatibility#1483
glensc merged 6 commits intoeventum:masterfrom
inguin:php8-fixes

Conversation

@inguin
Copy link
Copy Markdown
Contributor

@inguin inguin commented Jan 13, 2023

See individual commits for details.

@glensc
Copy link
Copy Markdown
Member

glensc commented Jan 13, 2023

So now you just omit escapeInteger calls, making code less secure again?

@vladsf
Copy link
Copy Markdown
Contributor

vladsf commented Jan 13, 2023

The 'sort_by' parameter is validated in saveSearchParams(), so there
should be no need for quoting.

What if $sort_by is later used unaware of being unquoted?

@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 13, 2023

So now you just omit escapeInteger calls, making code less secure again?

The entire search profile is serialized upon save, so there should be no need for escaping at this point.

The individual values are still escaped in buildWhereClause().

@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 13, 2023

What if $sort_by is later used unaware of being unquoted?

I'm not sure what the concern is. $sort_by holds the name of a known database column (one of SORT_BY_FIELDS). It should be perfectly safe to be used without quoting.

@vladsf
Copy link
Copy Markdown
Contributor

vladsf commented Jan 13, 2023

May be Misc::escapeInteger shall be replaced with Misc::escapeId which returns unsigned int or empty string?

@vladsf
Copy link
Copy Markdown
Contributor

vladsf commented Jan 13, 2023

What if $sort_by is later used unaware of being unquoted?

I'm not sure what the concern is. $sort_by holds the name of a known database column (one of SORT_BY_FIELDS). It should be perfectly safe to be used without quoting.

Not sure I understand. Right on the next line below $sort_by is used unescaped in SQL query:
SQL query

I guess this is unsafe. How could that be missed?

@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 13, 2023

Right a few lines below $sort_by is used unescaped in SQL query: SQL query

I guess this is unsafe.

No, it's not, because saveSearchParams() uses a whitelist to make sure that the only possible values are last_action_date, pri_rank, iss_id, sta_rank, iss_summary, or custom_field. (BTW, custom_field is a separate branch without any quoting even before my change).

The call to quoteIdentifier() was introduced on Nov 9 2021 (c732276).
The whitelist was introduced one day later (9119c50), making the quoting redundant.

If you feel it's safer I can also change the regexp to deal with quoted identifiers.

@vladsf
Copy link
Copy Markdown
Contributor

vladsf commented Jan 13, 2023

saveSearchParams() method used to save the current search parameters in a cookie, on a user side. Cookies are editable by user no matter what whitelists were used.

@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 13, 2023

Cookies are editable by user no matter what whitelists were used.

No cookies are involved as far as I know.

Search filters are taken from the request ($_GET or $_POST), or the search profile persisted in the database.

@vladsf
Copy link
Copy Markdown
Contributor

vladsf commented Jan 13, 2023

So $options['sort_by'] directly comes from GET/POST request? Is that correct?

@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 13, 2023

So $options['sort_by'] directly comes from GET/POST request? Is that correct?

Correct, with validation against SORT_BY_FIELDS.

@vladsf
Copy link
Copy Markdown
Contributor

vladsf commented Jan 13, 2023

Sorry I can not find it. Please point me the line where $options['sort_by'] is sanitized or validated.

@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 13, 2023

Sorry I can not find it. Please point me the line where $options['sort_by'] is sanitized or validated.

class.search.php, line 92

@glensc

This comment was marked as resolved.

@inguin

This comment was marked as resolved.

@vladsf
Copy link
Copy Markdown
Contributor

vladsf commented Jan 13, 2023

Sorry I can not find it. Please point me the line where $options['sort_by'] is sanitized or validated.

class.search.php, line 92

OK, I can see now. Yet this is so inconsistent and might hit once day later. I stop my ranting. Let's wait for @glensc.

@glensc
Copy link
Copy Markdown
Member

glensc commented Jan 16, 2023

Is this ready for merge? please rebase against origin/master. I won't do deep review, but looks ok.

@glensc glensc added this to the 3.10.13 milestone Jan 16, 2023
@glensc
Copy link
Copy Markdown
Member

glensc commented Jan 16, 2023

please also modify composer.json to allow php versions you tested. don't don't forget to update composer.lock

Some pages, e.g. login.php, do not set the "messages" template
parameter. Suppressing the resulting exception with @ no longer seems to
work with PHP 8.
The "any" option in search fields is identified by an empty string.
Calling escapeInteger() will convert those to 0. So far this did not
cause problems because 0 and "" compare equal; this is no longer the
case with PHP 8.
The quick filter form defines hidden input fields for the previous
values of date search options, but not for the end date ("between"
filter type). This causes an exception when saving the search profile.

Add the missing fields for end dates. To reduce code duplication, use a
Smarty section to loop through the various date fields.
Quoting the identifier breaks the regular expression in
Pager::getTotalRows(), causing 0 issues to be displayed when sorting by
last action date.

The 'sort_by' parameter is validated in saveSearchParams(), so there
should be no need for quoting.
@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 17, 2023

please also modify composer.json to allow php versions you tested.

I'm testing with PHP 8.1.14 (Fedora 37) and PHP 8.2.1 (CentOS 7.9). composer.json requires ^8.0, which should cover both.

@glensc
Copy link
Copy Markdown
Member

glensc commented Jan 17, 2023

they say that php engine versions aren't following semver, so ~8.0, ~8.1, ~8.2 would be more accurate to say, so it wouldn't include 8.3

@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 17, 2023

they say that php engine versions aren't following semver, so ~8.0, ~8.1, ~8.2 would be more accurate to say, so it wouldn't include 8.3

OK, makes sense. Done.

@glensc
Copy link
Copy Markdown
Member

glensc commented Jan 17, 2023

Your lock update is wrong, you ran composer update, updating all dependencies, I asked to run composer update --lock.

Doesn't make sense to put changelog and composer.json change to same commit, totally different changes. not atomic commit. now if I want to revert the composer.json commit I will also revert changelog change as it's same commit. that's about atomic commits principle.

and "update composer.json" is a clickbait commit title. have to git show to see what the change is about :) "Allow PHP 8.0-8.2 PHP versions in composer" would be a more appropriate title.

@glensc
Copy link
Copy Markdown
Member

glensc commented Jan 17, 2023

Oh, I didn't realize "^8.0" is already there from 2019:

@inguin
Copy link
Copy Markdown
Contributor Author

inguin commented Jan 17, 2023

Oh, I didn't realize "^8.0" is already there from 2019

I thought that why you asked to make it more specific. 😁

Want me to drop the commit?

@glensc
Copy link
Copy Markdown
Member

glensc commented Jan 17, 2023

I thought that why you asked to make it more specific. 😁

yes, we wanted and you agreed. so do it. but properly this time :)

@glensc glensc merged commit b4ca24b into eventum:master Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants