Skip to content

Potential fix for code scanning alert no. 6: Unsafe HTML constructed from library input#241

Merged
projectedanx merged 4 commits into
masterfrom
alert-autofix-6
Jul 6, 2026
Merged

Potential fix for code scanning alert no. 6: Unsafe HTML constructed from library input#241
projectedanx merged 4 commits into
masterfrom
alert-autofix-6

Conversation

@projectedanx

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/projectedanx/YOURLS/security/code-scanning/6

Best fix: stop constructing yearselect (and adjacent select/day labels) via raw HTML string concatenation with dynamic values. Build DOM nodes with jQuery element constructors, and assign dynamic content with .text(...) (or new Option(...)) so values are treated as text, not HTML.

In js/jquery.cal.js, inside newDatepickerHTML() (around lines 86–99), replace:

  • string-built monthselect / yearselect
  • the large concatenated <thead> appends using those strings

with safe DOM construction:

  • create <select name="month"> and <select name="year"> elements via jQuery('<select ...>')
  • append <option> elements using .val(...) and .text(...)
  • create the controls row and day-header row with element objects, using .text(...) for localized labels
  • append spans for prev/next/today/close using .text(...)

This preserves functionality while removing HTML injection risk from library input.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…from library input

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Daniel Hart | ALifeInArtifyAI <238904666+projectedanx@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@projectedanx projectedanx marked this pull request as ready for review July 6, 2026 14:25

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the calendar generation logic in js/jquery.cal.js to construct DOM elements dynamically using jQuery instead of concatenating raw HTML strings, which improves security and maintainability. The feedback suggests replacing the for...in loops used for iterating over months and years with safer alternatives, such as jQuery.each and a standard for loop, to prevent issues with prototype chain extensions and ensure correct iteration order.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread js/jquery.cal.js Outdated
Comment thread js/jquery.cal.js Outdated
projectedanx and others added 2 commits July 7, 2026 00:26
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Daniel Hart | ALifeInArtifyAI <238904666+projectedanx@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Daniel Hart | ALifeInArtifyAI <238904666+projectedanx@users.noreply.github.com>
@projectedanx projectedanx merged commit 1e32d73 into master Jul 6, 2026
15 of 16 checks passed
@projectedanx projectedanx deleted the alert-autofix-6 branch July 6, 2026 14:28
Comment thread js/jquery.cal.js

var tfootRow = jQuery('<tr></tr>');
tfootRow.append(jQuery('<td colspan="2"></td>').append(jQuery('<span class="today"></span>').text(l10n_cal_today)));
tfootRow.append(jQuery('<td colspan="3"></td>').html('&nbsp;'));
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