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

Blind sql injection fixes rework (#3284) #3316

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

jekkos
Copy link
Member

@jekkos jekkos commented Sep 27, 2021

I have reinstated the fix from a month ago. Want to get this out to release the 3.3.6.

@jekkos jekkos force-pushed the fix-sqli-rework branch 3 times, most recently from 80226a2 to cfe9271 Compare September 27, 2021 22:28
@odiea
Copy link
Collaborator

odiea commented Sep 27, 2021

Applying this to Items the only column that sorts is the Item_id column. All other columns just sort the Item_id.

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Thanks for testing @odiea I have checked your comment. Which column were you trying to sort? If I sort on name or category it does seem to work

sorting on barcode
Screenshot from 2021-09-28 09-22-07
Screenshot from 2021-09-28 09-22-01

sorting on name

Screenshot from 2021-09-28 09-21-50
Screenshot from 2021-09-28 09-21-56

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

Here is what I see. This was sorting on Name or Wholesale Price.
2021-09-28 02_03_04-Open Source Point of Sale _ Powered by OSPOS 3 3 5
2021-09-28 02_03_31-Open Source Point of Sale _ Powered by OSPOS 3 3 5
2021-09-28 02_04_00-Open Source Point of Sale _ Powered by OSPOS 3 3 5

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Ok weird, both cases seem to work fine on my end. I did force push a couple of times. Do you have the latest hash in use for the branch?

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

I downloaded this branch. © 2010 - 2021 · opensourcepos.org · 3.3.5 - 4b12b7.

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Ok thanks for the feedback, I have deployed the version to dev now and was checking, the name field does not sort correctly. I think the others do in fact.

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

Here is the code that I am testing out in Items.
$sort = $this->Item->sort_column($this->input->get('sort')); // controller
public function sort_column($field)
{
return array_key_exists($field, $this->db->list_fields('items')) ? $field : 'item_id';
} // model

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Think it should be cfe927

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Indeed there is still issue, I'll try to debug it, thanks for the feedback

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

I tried changing this and it appears to sort the columns correctly now.
From
return in_array($field, $this->db->list_fields('items')) ? $field : 'item_id';
To
return array_key_exists($field, $this->db->list_fields('items')) ? 'item_id' : $field;

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Did another push and seems better now on dev.

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

The only quirk I see now is on an older established db quantities does not sort? Looks ok on the Demo

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

@odiea you mean the regular quantities field?

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

Yes the Quantity field in the Items table

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

@odiea should be fixed now.

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

Yes it is. Works good now.

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

What is the issue with placing the id before the $field? I have had to do this to get some of the other tables to sort correctly. I guess the way I see it is the first table sort is the id and if that is not chosen then the fields are chosen.

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Well what the logic does it it checks if the supplied sorting column exists in the db, then applies it.

If some hacker tries to pass in some SQL for injection, it will be ignored as we only allow to sort on db column names.

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

But this does not appear to work correctly. I tried sorting in Customers, Suppliers and Employees and columns do not sort properly. The columns appear to sort to the id and not the column.

@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Indeed well spotted, I think those three models need one more adapation

@odiea
Copy link
Collaborator

odiea commented Sep 28, 2021

Try something on Gift cards and you may be done with this

@daN4cat daN4cat added this to the 3.3.6 milestone Sep 28, 2021
@daN4cat daN4cat added the bug label Sep 28, 2021
@jekkos
Copy link
Member Author

jekkos commented Sep 28, 2021

Ok the columns for giftcards are extended now. I've gotten two more security bug reports through this huntr.dev platform today. Not sure how this works but it seems that some researchers are looking for security bugs in ospos now.. which is good.

@jekkos
Copy link
Member Author

jekkos commented Sep 29, 2021

The sale table might not work correctly yet.. The current approach will do some extra queries to fetch the database column names, which do not necessarily map to the column headers names.

I had a further look and there might be a better solution. The header names are already defined in the tabular_helper, but they are not in an accessible place. It might be better to extract those header arrays somewhere and then check for the field presence in each array separately.

@jekkos jekkos marked this pull request as draft October 1, 2021 06:32
@jekkos jekkos removed this from the 3.3.6 milestone Jan 6, 2022
@jekkos
Copy link
Member Author

jekkos commented Mar 31, 2022

I should revisit this fix at some point..

@jekkos
Copy link
Member Author

jekkos commented Apr 10, 2024

Links to #3965

@jekkos jekkos added this to the 3.4.0 milestone Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants