This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.


Welcome To openGauss Community
Hey @Setname , thanks for your contribution to the community.
Bot Usage Manual
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.
Contact Guide
If you have any questions, please contact the SIG: Community ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @Igali, @libiao2024, @wangtianyuan1994, @zhangxubo .


自验结果:python -B -m unittest advisor.index_advisor.test.test_postgres_env,5/5 通过

测试代码可以在以下目录查看:
advisor/index_advisor/test/test_postgres_env.py
本次修复为安全补充修复,通过ut覆盖。
可以通过以下命令复测:
python -B -m unittest advisor.index_advisor.test.test_postgres_env


验收日期:2026-8-12
验收版本:7.0.0.B017
验收结论:验收通过





测试类型
工具功能
测试版本
7.0.0-RC3
问题描述
advisor/index_advisor/postgres_env.py在构造部分 PostgreSQL/openGauss SQL 时使用 Python%拼接动态值。表名、列名及 HypoPG index ID 可能直接进入最终 SQL;当这些值包含引号或特殊 SQL 语法时,可能改变语句语义,形成潜在 SQL 注入风险。涉及范围:
information_schema.columns的表名查询;step()和cal_cur_cost()中的hypopg_create_indexDDL;step()中的hypopg_relation_sizeindex ID 查询。操作系统和硬件信息
Host: Windows with Docker Desktop
Container image:
swr.cn-north-4.myhuaweicloud.com/kunpeng-ai/opengauss-distributed:0328Database: openGauss-lite 7.0.0-RC3
测试环境
轻量版容器化
被测功能
advisor/index_advisor/postgres_env.py预置条件
操作步骤
postgresql_env,触发 catalog 查询。step()或cal_cur_cost()创建 HypoPG 假想索引。预期输出
psycopg2.sql.SQL和psycopg2.sql.Identifier组成;hypopg_create_index;EXPLAIN {sql}保持不变,benchmark SQL 语义不发生变化。实际输出
原实现通过
%将表名、列名和 index ID 直接拼入 SQL 文本,未区分 SQL 结构、标识符和数据参数。安全扫描因此报告多处潜在 SQL 注入风险。日志信息
相关旧代码模式:
WHERE table_name='%s'% table;hypopg_create_index('CREATE INDEX ON %s (%s)')% (table_name, column_name);hypopg_relation_size(%s)% str(index_id)。提单组织
开发自提