PrivateBin / PrivateBin

A minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted in the browser using 256 bits AES.
https://privatebin.info/
Other
6.57k stars 815 forks source link

Numeric array key type errors #1438

Closed elrido closed 4 weeks ago

elrido commented 1 month ago

This PR fixes #1435

Changes

ToDo

There are two other areas I found that might have the same issue, but have not been able to trigger the issue from the outside - please review and share your thoughts:

So I think that at this time both of the above cases are un-problematic, but could be potential future foot-guns if used incorrectly?

rugk commented 1 month ago

Thanks a lot! This seems like the proper fix.

About your concerns:

So yeah hard to trigger from the outside, but IMHO, we could anyway do explicit casts, if you've already identified it as a problem, IMHO. I mean casting strings explicitly to a string won't hurt, does it? I.e. let's fix the problem even if we have no unit test to prevent breakage.

elrido commented 1 month ago

I do not want to add the casts blindly if I can't create a test that trigger a problem.

For the config I tried to write one where I pass a config file that contains a numeric key, but that simply gets ignored by the loop, since we loop over known default keys. In general, if people add things to our config files that are not in the defaults, they will get ignored and are not accessible through the Configuration object. The internal config is based on the defaults, with the config file values replacing the default.

In the database case it is a flat array (i.e. array('first param', 'second param'), so keys are expected to always be int (i.e. 0, 1 for the previous example). The only reason they would not be, is if someone added a call to exec_ passing an incorrect array (with string key) and then that PDO prepared statement call would fail because the bound params would not line up with the ? mark in the query. So it is unlikely to get added and remain undetected, unless we don't write a test for the new code path.

rugk commented 1 month ago

Okay then though our config should be safe.

And okay, though I would have said a cast to the correct type does not hurt and an incorrect case would be detected as it breaks everything(?). So yeah…

github-actions[bot] commented 1 month ago

Test Results

    8 files  ±0    148 suites  ±0   1m 21s ⏱️ ±0s   346 tests +1    330 ✅ +2  0 💤 ±0  0 ❌ ±0  16 🔥  - 1  1 804 runs  +7  1 788 ✅ +8  0 💤 ±0  0 ❌ ±0  16 🔥  - 1 

For more details on these errors, see this check.

Results for commit 8752354d. ± Comparison against base commit d23bb748.

:recycle: This comment has been updated with latest results.

elrido commented 1 month ago

I also restated the database prepared statement argument binding to use a regular incremented position variable. That doesn't require using keys. Possibly more readable, too?

rugk commented 1 month ago

Thanks! LGTM.