Skip to content

Fix security vulnerabilities, async bugs, and timing issues in FPC worker#9

Draft
Genaker with Copilot wants to merge 7 commits into
mainfrom
copilot/review-suggestions
Draft

Fix security vulnerabilities, async bugs, and timing issues in FPC worker#9
Genaker with Copilot wants to merge 7 commits into
mainfrom
copilot/review-suggestions

Conversation

Copilot AI commented Feb 10, 2026

Copy link
Copy Markdown

Code review identified critical bugs in cache worker: missing radix parameters causing potential octal interpretation, async forEach not awaiting ESI fragments, and KV sync timing comparing milliseconds to seconds.

Security & Correctness

parseInt radix - Added explicit base-10 to 7 calls preventing octal/hex misinterpretation:

// Critical in Content-Length checks and cache versioning
parseInt(response.headers.get('age') || '0', 10)

Null header access - Added fallback values at 3 header access points to prevent runtime errors.

Hostname validation - Added regex for OTHER_HOST to prevent DNS rebinding:

OTHER_HOST.match(/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*(:[0-9]{1,5})?$/i)

Bug Fixes

ESI async processing - Replaced forEach(async ...) with Promise.all + map. Previous code didn't await, causing replacements to fail silently:

// Now properly awaits all text() calls in parallel
const textPromises = results.map(async (result, ind) => {
  try {
    return result.status === 200 ? await result.text() : "<!--ESI not 200-->";
  } catch (error) {
    return "<!--ESI error-->";
  }
});
const texts = await Promise.all(textPromises);

KV config sync timing - Fixed comparison === 360 (never true) to > 360000 (6 minutes in ms). Moved timestamp reset before sync to prevent interval drift.

Code Quality

  • Fixed variable typo: R2_CAHE_LOGGEDIN_USERSR2_CACHE_LOGGED_IN_USERS
  • Removed dead code: unused options variable in cache bypass check
  • Fixed 10+ comment typos (simultaneously, received, instead, etc.)
  • Removed "nodejent" from package.json keywords

Documentation

  • Created SECURITY.md covering environment variables, ESI risks, and mitigation strategies
  • Fixed README typos: Cockies→Cookies, Chache→Cache, malformed HTML tags
  • Created IMPROVEMENTS.md with detailed change log

CodeQL: 0 alerts. All changes backward compatible.

Original prompt

Review and suggest not improvements


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 6 commits February 10, 2026 08:23
Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
…sm, add port support

Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
Copilot AI changed the title [WIP] Review and suggest improvements Fix security vulnerabilities, async bugs, and timing issues in FPC worker Feb 10, 2026
Copilot AI requested a review from Genaker February 10, 2026 08:34
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