Skip to content

stats/teams: Use escaping instead of interpolation when building SQL - #1716

Merged
cpeel merged 2 commits into
DistributedProofreaders:masterfrom
bpfoley:teams-escape
Nov 22, 2026
Merged

cpeel merged 2 commits into
DistributedProofreaders:masterfrom
bpfoley:teams-escape

Conversation

@bpfoley

@bpfoley bpfoley commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

As it turns out all the interpolated strings are integers or are entirely generated from code rather than user-controlled input, so this doesn't fix any exploitable issue, but it makes it clearer to static analysis tools and human readers.

Comment thread stats/includes/team.inc Outdated

if (!empty($_FILES['teamavatar']['tmp_name']) && ($type == "both" || $type == "avatar")) {
if (strtolower(substr($_FILES['teamavatar']['name'], -4)) == ".png" || strtolower(substr($_FILES['teamavatar']['name'], -4)) == ".jpg" || strtolower(substr($_FILES['teamavatar']['name'], -4)) == ".gif") {
$extension = strrchr(strtolower($_FILES['teamavatar']['name']), '.');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should we use tools like pathinfo instead of manually parsing the string? I worry about things like evil.svg.jpg that may in certain contexts get interpreted as SVG with malicious Javascript or something. Maybe just enforce only one instance of . in the string as well as this extension check?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. We should use pathinfo. I ran across it later last night, and it turns out we parse filename extensions a few different ways in the codebase.

I specifically used strrchr to avoid the evil.svg.jpg scenario: it splits on the last . in the filename, but still, we may as well use pathinfo to avoid all doubt. I'll update the patch.

@bpfoley
bpfoley force-pushed the teams-escape branch 2 times, most recently from 2ced005 to ef1b0ed Compare November 17, 2026 21:04
As it turns out all the interpolated strings are integers or are
entirely generated from code rather than user-controlled input,
so this doesn't fix any exploitable issue, but it makes it clearer
to static analysis tools and human readers.
Note, the semantics are slightly different
1. pathinfo's extension doesn't have the leading '.'
2. pathinfo's filename is just the filename and not the entire path

The patch accounts for the leading '.', and the list of files being
processed is generated by glob('*') which generates a simple list of
filenamess in the current directory (and no subdirs), with no path.
@cpeel
cpeel merged commit 4957b14 into DistributedProofreaders:master Nov 22, 2026
12 checks passed
@bpfoley
bpfoley deleted the teams-escape branch November 22, 2026 21:29
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.

4 participants