douzhun8615 2016-12-01 15:49
浏览 17
已采纳

PrestaShop Validator:SQL安全问题

Good evening, I'm validating PrestaShop on my form. The mistake is reflected:

Your module contains security issues. - Make sure that your data is always protected when doing an insertion. For instance, make sure that you do have an integer with an explicit (int) cast, and that text is protected against SQL injections thanks to the pSQL() method. - Be careful (string) is not a secured cast, you must pSQL.

The insert query I use are as follows:

Db::getInstance()->execute('INSERT IGNORE INTO '._DB_PREFIX_.'ff_list_filter (name, content) VALUES ("'.$t['filter_template_name'].'","'.  str_replace('"', '\"', serialize($t)).'")');

or

Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.'ff_people` (`field`,`list`) VALUES ("'.$c->email.'",'.$listId.')');

or

Db::getInstance()->execute('INSERT IGNORE INTO '._DB_PREFIX_.'ff_custom_field (field, list) VALUES ("'.$field.'"," ","'.$list.'")');

Have you ever seen anything like that?

  • 写回答

1条回答 默认 最新

  • duan5362 2016-12-01 16:17
    关注

    Prestashop Addons validation process is very exquisite. This error means that you should cast all the external parameters you use in your SQL statement. Should be like this:

    Db::getInstance()->execute('INSERT IGNORE INTO '._DB_PREFIX_.'ff_list_filter (name, content) VALUES ("'. pSQL($t['filter_template_name']).'","'.  pSQL(str_replace('"', '\"',  serialize($t))).'")');
    

    If you have params with type is other than string you should cast directly to corresponding type:

    Db::getInstance()->execute('INSERT IGNORE INTO '._DB_PREFIX_.'ff_list_filter (name, content) VALUES ("'. (int) $t['id_int'].'","'.  pSQL(str_replace('"', '\"',  serialize($t))).'")');
    

    Additional suggestion. You could use more Prestashop's DB class in insert, update and delete sentences. This way avoid simple quotes errors or similar:

    Db::getInstance()->insert('ff_list_filter', array('name' => pSQL($t['filter_template_name']), 'content' => pSQL(str_replace('"', '\"',  serialize($t)))));
    

    Good luck.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)