CVE-2021-41262 (PHP, published 2021-12-16T19:15Z)
Description: value: Galette is a membership management web application built for non profit organizations and released under GPLv3. Versions prior to 0.9.6 are subject to SQL injection attacks by users with "member" privilege. Users are advised to upgrade to version 0.9.6 as soon as possible. There are no known workarounds.
Severity: MEDIUM (CVSS v3 base score: 8.8)
Weakness: CWE-89 \u2014 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
Repository: https://github.com/galette/galette
Files changed:
galette/lib/Galette/Core/Db.php
galette/lib/Galette/Core/Logo.php
galette/lib/Galette/Core/MailingHistory.php
galette/lib/Galette/Core/Password.php
galette/lib/Galette/Core/Picture.php
galette/lib/Galette/DynamicFields/DynamicField.php
galette/lib/Galette/Entity/Adherent.php
galette/lib/Galette/Entity/Contribution.php
galette/lib/Galette/Entity/Entitled.php
galette/lib/Galette/Entity/Group.php
galette/lib/Galette/Entity/ImportModel.php
galette/lib/Galette/Entity/PaymentType.php
galette/lib/Galette/Entity/PdfModel.php
galette/lib/Galette/Entity/Reminder.php
galette/lib/Galette/Entity/SavedSearch.php
galette/lib/Galette/Entity/Social.php
galette/lib/Galette/Entity/Title.php
galette/lib/Galette/Entity/Transaction.php
galette/lib/Galette/Repository/Groups.php
galette/lib/Galette/Repository/Members.php
Commit message: Use prepared statement rather than direct SQL


Vulnerable code:
 * Copyright © 2011-2014 The Galette Team
 * @copyright 2011-2014 The Galette Team
 * @copyright 2011-2014 The Galette Team
                    $select->where('test_id = 1');
                    $where[] = $k . ' = "' . $row->$k . '"';
 * Copyright © 2009-2014 The Galette Team
 * @copyright 2009-2014 The Galette Team
 * @copyright 2009-2014 The Galette Team
        $select->where(self::PK . ' = ' . $this->db_id);
            $select->where('mailing_id = ' . $id);
            $update->where(self::PK . ' = ' . $this->mailing->history_id);
 * Copyright © 2003-2020 The Galette Team
 * @copyright 2003-2014 The Galette Team
 * @copyright 2009-2020 The Galette Team
            $delete->where(self::PK . ' = ' . $id_adh);
 * Copyright © 2006-2014 The Galette Team
 * @copyright 2006-2014 The Galette Team
 * @copyright 2006-2014 The Galette Team
            $delete->where(
                $class::PK . ' = ' . $this->db_id
            );
            $select->where('field_id = ' . $id);
            $select->where(self::PK . ' = ' . $id);
                $update->set($values)->where(
                    self::PK . ' = ' . $this->id
                );
            )->where(
                'parent_id = ' . $this->_id
            );
            $select->where(self::PK . ' = ' . $id);
            )->where(self::PK . ' = ' . $id_adh);
                            $select->where(
                                self::PK . ' != ' . $this->_id
                                $select->where(
                                    self::PK . ' != ' . $this->_id
                    $select->where(Status::PK . '= ' . $value);
                $update->where(
                    self::PK . '=' . $this->_id
                );
            )->where(self::PK . '=' . $this->_id);
            )->where(Adherent::PK . ' = ' . $this->_member)
                $select->where(self::PK . ' != ' . $this->id);
                $update->set($values)->where(
                    self::PK . '=' . $this->_id
                );
                Adherent::PK . '=' . $this->_member
            $delete->where(self::PK . ' = ' . $this->_id);
                Adherent::PK . ' = ' . $member_id
                    self::PK . ' = ' . $contrib_id
            )->where(self::PK . ' = ' . $contrib_id);
            $select->where($this->fpk . ' = ' . $id);
            $select->where($this->fpk . '=' . $id);
            $update->where($this->fpk . ' = ' . $id);
            $delete->where($this->fpk . ' = ' . $id);
            $select->where($this->fpk . ' = ' . $id);
                )->where(
                    'g.' . self::PK . ' = ' . $this->id
                )->order(
                )->where('b.' . Adherent::PK . ' = ' . $this->login->id);
            $select->where('parent_group = ' . $this->id)
                $delete->where(
                    self::PK . ' = ' . $this->id
                );
                $delete->where(
                    self::PK . ' = ' . $this->id
                );
            $delete->where(
                self::PK . ' = ' . $this->id
            );
                self::PK . ' = ' . $this->id
                    ->where(self::PK . '=' . $this->id);
            $delete->where(
                self::PK . ' = ' . $this->id
            );
            $delete->where(
                self::PK . ' = ' . $this->id
            );
                $update->where(self::PK . '=' . $this->id);
            $select->limit(1)->where(self::PK . ' = ' . $id);
                $update->set($data)->where(
                    self::PK . '=' . $this->id
                );
            $delete->where(
                self::PK . ' = ' . $id
            );
                ->where(self::PK . ' = ' . $id);
                    self::PK . '=' . $this->id
                ->where(self::PK . ' = ' . $id);
            $select->limit(1)->where(self::PK . ' = ' . $id);
                $select->where(Adherent::PK . ' = ' . (int)$this->login->id);
            $delete->where(
                self::PK . ' = ' . $id
            );
            $select->limit(1)->where(self::PK . ' = ' . $id);
                    self::PK . '=' . $this->id
            $select->limit(1)->where(self::PK . ' = ' . $id);
                $update->set($data)->where(
                    self::PK . '=' . $this->id
                );
            $delete->where(
                self::PK . ' = ' . $id
            );
            $select->where(self::PK . ' = ' . $id);
            $delete->where(
                self::PK . ' = ' . $this->_id
            );
                $update->set($values)->where(
                    self::PK . '=' . $this->_id
                );
            )->where(self::PK . ' = ' . $this->_id);
            )->where(self::PK . ' = ' . $this->_id);
 * Copyright © 2011-2014 The Galette Team
 * @copyright 2011-2014 The Galette Team
 * @copyright 2011-2014 The Galette Team
                )->where('c.' . Adherent::PK . ' = ' . $this->login->id);
            $delete->where(
                Adherent::PK . ' = ' . $adh->id
            );
                    )->where('m.' . Adherent::PK . ' = ' . $login->id);
                    $subselect->where('df.field_form = \'adh\'');
                    $subselect->where('df.field_id = ' . $df);
                    '(g.' . Group::PK . ' = ' . $this->filters->group_filter .

Fixed code:
 * Copyright © 2011-2021 The Galette Team
 * @copyright 2011-2021 The Galette Team
 * @copyright 2011-2021 The Galette Team
                    $select->where(['test_id' => 1]);
                    $where[$k] = $row->$k;
 * Copyright © 2009-2021 The Galette Team
 * @copyright 2009-2021 The Galette Team
 * @copyright 2009-2021 The Galette Team
        $select->where([self::PK => $this->db_id]);
            $select->where(['mailing_id' => $id]);
            $update->where([self::PK => $this->mailing->history_id]);
 * Copyright © 2003-2021 The Galette Team
 * @copyright 2003-2021 The Galette Team
 * @copyright 2009-2021 The Galette Team
            $delete->where([self::PK => $id_adh]);
 * Copyright © 2006-2021 The Galette Team
 * @copyright 2006-2021 The Galette Team
 * @copyright 2006-2021 The Galette Team
            $delete->where([$class::PK => $this->db_id]);
            $select->where(['field_id' => $id]);
            $select->where([self::PK => $id]);
                $update->set($values)->where([self::PK => $this->id]);
            )->where(['parent_id' => $this->_id]);
            $select->where([self::PK => $id]);
            )->where([self::PK => $id_adh]);
                            $select->where->notEqualTo(
                                self::PK,
                                $this->_id
                                $select->where->notEqualTo(
                                    self::PK,
                                    $this->_id
                    $select->where([Status::PK => $value]);
                $update->where([self::PK => $this->_id]);
            )->where([self::PK => $this->_id]);
            )->where([Adherent::PK => $this->_member])
                $select->where->notEqualTo(self::PK, $this->id);
                $update->set($values)->where([self::PK => $this->_id]);
                [Adherent::PK => $this->_member]
            $delete->where([self::PK => $this->_id]);
                [Adherent::PK => $member_id]
                    [self::PK => $contrib_id]
            )->where([self::PK => $contrib_id]);
            $select->where([$this->fpk => $id]);
            $select->where([$this->fpk => $id]);
            $update->where([$this->fpk => $id]);
            $delete->where([$this->fpk => $id]);
            $select->where([$this->fpk => $id]);
                )->where([
                    'g.' . self::PK => $this->id
                ])->order(
                )->where(['b.' . Adherent::PK => $this->login->id]);
            $select->where(['parent_group' => $this->id])
                $delete->where([self::PK => $this->id]);
                $delete->where([self::PK => $this->id]);
            $delete->where([self::PK => $this->id]);
                [self::PK => $this->id]
                    ->where([self::PK => $this->id]);
            $delete->where([self::PK => $this->id]);
            $delete->where([self::PK => $this->id]);
                $update->where([self::PK => $this->id]);
            $select->limit(1)->where([self::PK => $id]);
                $update->set($data)->where([self::PK => $this->id]);
            $delete->where([self::PK => $id]);
                ->where([self::PK => $id]);
                    [self::PK => $this->id]
                ->where([self::PK => $id]);
            $select->limit(1)->where([self::PK => $id]);
                $select->where([Adherent::PK => $this->login->id]);
            $delete->where([self::PK => $id]);
            $select->limit(1)->where([self::PK => $id]);
                    [self::PK => $this->id]
            $select->limit(1)->where([self::PK => $id]);
                $update->set($data)->where([self::PK => $this->id]);
            $delete->where([self::PK => $id]);
            $select->where([self::PK => $id]);
            $delete->where([self::PK => $this->_id]);
                $update->set($values)->where([self::PK => $this->_id]);
            )->where([self::PK => $this->_id]);
            )->where([self::PK => $this->_id]);
 * Copyright © 2011-2021 The Galette Team
 * @copyright 2011-2021 The Galette Team
 * @copyright 2011-2021 The Galette Team
                )->where(['c.' . Adherent::PK => $this->login->id]);
            $delete->where([Adherent::PK => $adh->id]);
                    )->where(['m.' . Adherent::PK => $login->id]);
                    $subselect->where(['df.field_form' => 'adh']);
                    $subselect->where(['df.field_id' => $df]);
                    '(g.' . Group::PK . ' = ' . $zdb->platform->quoteValue($this->filters->group_filter) .