Skip to content

fix: escape user-controlled data in order.log() and objects_to_hyperlinks() - #2522

Open
TempleOfSats wants to merge 5 commits into
RoboSats:mainfrom
TempleOfSats:pr-20260705-170319-xss-escape-order-logs
Open

fix: escape user-controlled data in order.log() and objects_to_hyperlinks()#2522
TempleOfSats wants to merge 5 commits into
RoboSats:mainfrom
TempleOfSats:pr-20260705-170319-xss-escape-order-logs

Conversation

@TempleOfSats

Copy link
Copy Markdown
Contributor

Changes

1. api/models/order.py — log() method

  • Added escape() around level and event before storing in the logs HTML table row
  • Any user-controlled data (order IDs, usernames, addresses, descriptions, etc.) is now neutralized at the point of storage

2. api/utils.py — objects_to_hyperlinks() function

  • Added escape() on the entire logs string before regex substitution
  • Defense-in-depth: even if something slipped through the first escape, injected HTML/JS is rendered as text instead of being executed

Security Impact

Both fixes prevent XSS attacks via the order logs system.

…inks()

- api/models/order.py: escape() level and event before storing in logs
  to prevent XSS via order IDs, usernames, addresses, descriptions etc.
- api/utils.py: escape() entire logs string before regex substitution
  in objects_to_hyperlinks() as defense-in-depth against injected HTML/JS
@jerryfletcher21

Copy link
Copy Markdown
Contributor

The change in api/utils.py renders the logs unreadable in the admin panel

gabbygator184 added a commit that referenced this pull request Jul 16, 2026
…inks()

- api/models/order.py: escape() level and event before storing in logs
  to prevent XSS via order IDs, usernames, addresses, descriptions etc.
- api/utils.py: escape() entire logs string before regex substitution
  in objects_to_hyperlinks() as defense-in-depth against injected HTML/JS
#2522
gabbygator184
gabbygator184 previously approved these changes Aug 1, 2026
@alicecoordinator

Copy link
Copy Markdown
Contributor

As @jerryfletcher21 pointed out, this will break the rendering. There are also places in the code that add logs containing HTML tags.

I think we should fix this by converting the logs column into a JSON column, then having the log message containing plain-text only, but with a few special behavior, like the existing objects_to_hyperlinks, which would allow some very-limited markdown-style formatting.

KoalaSat
KoalaSat previously approved these changes Aug 7, 2026
@KoalaSat
KoalaSat self-requested a review August 7, 2026 09:28
@KoalaSat

KoalaSat commented Aug 7, 2026

Copy link
Copy Markdown
Member

@TempleOfSats any update on this?

gabbygator184
gabbygator184 previously approved these changes Aug 7, 2026
@TempleOfSats
TempleOfSats dismissed stale reviews from gabbygator184 and KoalaSat via c1831bc August 12, 2026 07:17
Comment thread api/admin.py
except Exception as e:
html_logs = f"An error occurred while formatting the parsed logs as HTML. Exception {e}"
return html_logs
return format_html(render_order_logs(obj.logs))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It make more sense to use mark_safe instead of format_html. I wrote the reason in this PR: #2423.

@alicecoordinator

Copy link
Copy Markdown
Contributor

Well done!

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.

5 participants