Skip to content

fix SQL injection: intval each element in hlist before SQL IN clause#1143

Merged
zhblue merged 3 commits intomasterfrom
fix-sql-injection-hlist
Mar 30, 2026
Merged

fix SQL injection: intval each element in hlist before SQL IN clause#1143
zhblue merged 3 commits intomasterfrom
fix-sql-injection-hlist

Conversation

@zhblue
Copy link
Copy Markdown
Owner

@zhblue zhblue commented Mar 30, 2026

Fix SQL Injection via hlist parameter

问题

admin/problem_df_change.phpadmin/contest_add.php 中,hlist 参数绕过 intval() 保护,直接拼入 SQL IN 子句。

修复

对 hlist 拆分后的每个元素强制 intval:

$plist = implode(",", array_map('intval', $pieces));

涉及文件

  • admin/problem_df_change.php
  • admin/contest_add.php

- admin/problem_df_change.php: wrap hlist processing in braces and apply array_map intval
- admin/contest_add.php: same fix for hlist bypass of intval protection
Copilot AI review requested due to automatic review settings March 30, 2026 02:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens admin-side bulk operations by sanitizing the hlist parameter before it’s interpolated into SQL IN (...) clauses, reducing the risk of SQL injection via crafted list inputs.

Changes:

  • In problem_df_change.php, sanitize each hlist element via intval before building the IN (...) list.
  • In contest_add.php, apply the same per-element intval sanitization when consuming hlist.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
trunk/web/admin/problem_df_change.php Sanitizes hlist elements prior to SQL IN (...) usage when enabling/disabling problems.
trunk/web/admin/contest_add.php Sanitizes hlist elements used when creating a contest from selected problems.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +149 to +153
$pieces = explode(",",$plist);
$pieces = array_unique($pieces);
if($pieces[0]=="") unset($pieces[0]);
$plist=implode(",",$pieces);
// 安全修复:每个ID元素强制intval,防止SQL注入
$plist = implode(",", array_map('intval', $pieces));
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here array_map('intval', $pieces) can turn empty segments (e.g., a trailing comma in hlist) into 0, so $plist may include 0 even when no valid IDs were selected. Filter the exploded values to valid positive integers (and reindex) before implode to avoid creating ...,0,... or an all-"0" list.

Copilot uses AI. Check for mistakes.
@zhblue zhblue merged commit d94ac2c into master Mar 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants