fix SQL injection: intval each element in hlist before SQL IN clause#1143
Merged
fix SQL injection: intval each element in hlist before SQL IN clause#1143
Conversation
- 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
Contributor
There was a problem hiding this comment.
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 eachhlistelement viaintvalbefore building theIN (...)list. - In
contest_add.php, apply the same per-elementintvalsanitization when consuminghlist.
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)); |
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix SQL Injection via hlist parameter
问题
admin/problem_df_change.php和admin/contest_add.php中,hlist 参数绕过 intval() 保护,直接拼入 SQL IN 子句。修复
对 hlist 拆分后的每个元素强制 intval:
涉及文件
admin/problem_df_change.phpadmin/contest_add.php