Skip to content

Reflected XSS in search functionality #3

@RinZ27

Description

@RinZ27

The search implementation in js/search.js is currently vulnerable to Reflected XSS. Specifically, the user-supplied query is directly concatenated into the innerHTML of the search results container without any sanitization or escaping.

A malicious actor could craft a URL containing a payload like <img src=x onerror=alert(1)> which would execute arbitrary JavaScript in the user's browser when the search results are rendered.

I've already prepared a fix that introduces a helper function to escape HTML entities and applies it to the query before rendering.

  function escapeHTML(str) {
    if (!str) return '';
    return str.replace(/[&<>"']/g, function (m) {
      return {
        '&': '&amp;',
        '<': '&lt;',
        '>': '&gt;',
        '"': '&quot;',
        "'": '&#39;'
      }[m];
    });
  }

This ensures that both the "no results" hint and the highlighted matches are handled safely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions