Skip to content

Security: fix four vulnerabilities in autocomplete app#19

Merged
gb119 merged 3 commits into
mainfrom
copilot/audit-security-in-autocomplete-app
Mar 2, 2026
Merged

Security: fix four vulnerabilities in autocomplete app#19
gb119 merged 3 commits into
mainfrom
copilot/audit-security-in-autocomplete-app

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

The autocomplete app had four security issues: unauthenticated access to data-exposing endpoints, a reflected XSS via inline JS event handlers, an unhandled 500 on bad URL parameters, and an HTML attribute injection via unescaped component_prefix.

Changes

Critical – Block unauthenticated access by default (core.py)

auth_check previously used AUTOCOMPLETE_BLOCK_UNAUTHENTICATED defaulting to False, meaning all autocomplete endpoints (users, equipment, cost centres) were reachable without a session. Inverted to deny by default; opt-out via AUTOCOMPLETE_ALLOW_UNAUTHENTICATED = True.

High – XSS via component_id in inline event handler (textinput.html)

<!-- before -->
onblur="..., '{{ component_id }}', ..."
<!-- after -->
onblur="..., '{{ component_id|escapejs }}', ..."

Django's HTML auto-escaping converts '&#x27;, but the browser decodes entities before executing the event handler, allowing field_name=x'); alert(1); // to break out of the string. escapejs backslash-escapes JS special characters instead.

Medium – 500 on unknown ac_name → 404 (views.py)

ac_class raised an unhandled ValueError for unregistered names; changed to Http404.

Medium – component_prefix attribute injection (templatetags/autocomplete.py)

component_prefix was embedded in a single-quote-delimited hx-vals attribute without HTML escaping. A ' in the value terminates the attribute early, enabling e.g. onmouseover='...' injection. Applied escape() consistently with field_name.

Tests

Added apps/autocomplete/tests.py (12 tests) covering auth enforcement, 404 behaviour, hx-vals escaping, and XSS safety of the search_highlight filter.


💡 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 2 commits March 2, 2026 22:42
Co-authored-by: gb119 <4428426+gb119@users.noreply.github.com>
Co-authored-by: gb119 <4428426+gb119@users.noreply.github.com>
Copilot AI changed the title [WIP] Audit autocomplete app for security issues and propose fixes Security: fix four vulnerabilities in autocomplete app Mar 2, 2026
Copilot finished work on behalf of gb119 March 2, 2026 22:45
@gb119 gb119 marked this pull request as ready for review March 2, 2026 23:47
@gb119 gb119 merged commit 3723024 into main Mar 2, 2026
2 checks passed
@gb119 gb119 deleted the copilot/audit-security-in-autocomplete-app branch March 2, 2026 23:48
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