Bug 37861 - Fix XSS vulnerability in barcode append function
Summary: Fix XSS vulnerability in barcode append function
Status: Pushed to oldoldstable
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P4 normal
Assignee: Artur
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-07 16:11 UTC by Artur
Modified: 2024-11-13 16:23 UTC (History)
18 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00,24.05.05,23.11.10,23.05.16,22.11.22
Circulation function:


Attachments
Ignore (4.30 KB, text/plain)
2024-09-07 16:18 UTC, Artur
Details
Bug 37861: Fix XSS vulnerability by sanitizing user input in barcode append function. (4.28 KB, patch)
2024-09-07 21:24 UTC, Artur
Details | Diff | Splinter Review
Bug 37861: Fix XSS vulnerability by sanitizing user input in barcode append function. (4.27 KB, patch)
2024-09-10 19:05 UTC, Bosse
Details | Diff | Splinter Review
Bug 37861: Fix XSS vulnerability in barcode append function (4.32 KB, patch)
2024-10-17 21:44 UTC, Chris Cormack
Details | Diff | Splinter Review
New patch file that’s formatted correctly. (4.32 KB, patch)
2024-11-09 11:21 UTC, Artur
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Artur 2024-09-07 16:11:41 UTC
When user inputs were appended directly to the barcode table, the values were not properly escaped, allowing potential XSS attacks.
Comment 1 Artur 2024-09-07 16:18:43 UTC
Created attachment 171164 [details]
Ignore
Comment 2 Artur 2024-09-07 21:24:07 UTC
Created attachment 171165 [details] [review]
Bug 37861: Fix XSS vulnerability by sanitizing user input in barcode append function.
Comment 3 Katrin Fischer 2024-09-08 08:36:43 UTC
Hi Artur, please file any potential security bugs/vulnerabilities in the 'Koha security' project. They will be fully published after testing and fixing.
Comment 4 Bosse 2024-09-10 19:05:06 UTC
Created attachment 171279 [details] [review]
Bug 37861: Fix XSS vulnerability by sanitizing user input in barcode append function.

Signed-off-by: Bo Gustavsson <bosse@gustavsson.one>
Comment 5 Artur 2024-09-13 07:36:12 UTC
(In reply to Katrin Fischer from comment #3)
> Hi Artur, please file any potential security bugs/vulnerabilities in the
> 'Koha security' project. They will be fully published after testing and
> fixing.

Thank you, sorry for making you call me out more than once. I also wonder if I’ve done everything correctly so far, or if I need to do something more before my patch can get a QA.
Comment 6 Katrin Fischer 2024-09-16 11:54:10 UTC
I am a bit worried that a fix in JS might not be enough here. Should we not validate server side too?
Comment 7 Artur 2024-09-16 20:43:55 UTC
No. The script injected only runs on the client who did the injection. It does send the text to the server, but the server only makes a check for a matching book in the database, nothing else. Maybe I should change the name of this bug to script injection instead of xss because it isn’t cross-site. If so, should I also remove the bug from Kona Security.
Comment 8 David Cook 2024-09-24 17:41:29 UTC
At a quick glance, it looks like this code could work, but we'll want to review it further (probably after Kohacon).
Comment 9 Artur 2024-10-11 07:54:56 UTC
Pls QA
Comment 10 David Cook 2024-10-14 02:55:20 UTC
(In reply to Artur from comment #9)
> Pls QA

It's in the queue ;)
Comment 11 Artur 2024-10-14 06:20:35 UTC
Thank you
Comment 12 Chris Cormack 2024-10-17 21:42:37 UTC
Seems to work and yes it makes more sense now you explain it isnt XSS as you cant trigger someone else to run it. Good to stop it anyway.

I'll QA it
Comment 13 Chris Cormack 2024-10-17 21:44:42 UTC
Created attachment 172931 [details] [review]
Bug 37861: Fix XSS vulnerability in barcode append function

When user inputs were appended directly to the barcode table, the values were not properly escaped, allowing potential XSS attacks. This patch ensures that user inputs are sanitized and safely added to the DOM using .text() and .attr() methods to prevent script injection.

To test:
Enable the "SelfCheckInModule".
Open the barcode input form.
Enter a barcode with HTML or script tags.
Without the patch, observe that the script is executed.
Apply the patch.
Repeat step 2.
Verify that the input is escaped and no script execution occurs.
Check that the barcode is properly appended to the table.

Documentation:
No updates required.

Sponsored-by:
KillerRabbitAos

Signed-off-by: Bo Gustavsson <bosse@gustavsson.one>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Comment 14 Artur 2024-10-19 17:50:02 UTC
My patch also fixes the bug where you can submit empty books. That bug already has a pushed patch but this is (in my opinion) a more elegant solution. Avoiding adding extra event listeners.
Comment 15 Wainui Witika-Park 2024-10-23 22:16:33 UTC
Applied to 23.05.x-security for 23.05.16
Comment 16 Wainui Witika-Park 2024-11-05 00:44:47 UTC
When generating release notes, I was getting this error:

root@9807bee652dc:/koha# koha-release v23.05.15..HEAD notes
23.05.16.000
<sponsor>
 does not match expected output for git check-mailmap at /release-tools/lib/Koha/Release.pm line 310.

Figured out that it was because of this:

Sponsored-by:
KillerRabbitAos

It needs to be on the same line, like this:

Sponsored-by: KillerRabbitAos

I fixed it on my branch but just letting other rmaints etc know :)
Comment 17 Fridolin Somers 2024-11-05 14:48:56 UTC
Applied to 23.11.x-security for v23.11.10
Comment 18 Artur 2024-11-06 07:45:56 UTC
What does applied to mean? And how does security versions work. I’m sorry for being such a pain, I’m just getting the hang of Koha and have my ways of missing stuff in the documentation.
Comment 19 Artur 2024-11-09 11:21:38 UTC
Created attachment 174312 [details] [review]
New patch file that’s formatted correctly.
Comment 20 Wainui Witika-Park 2024-11-11 02:06:20 UTC
(In reply to Artur from comment #18)
> What does applied to mean? And how does security versions work. I’m sorry
> for being such a pain, I’m just getting the hang of Koha and have my ways of
> missing stuff in the documentation.

Hi Artur,

Applied means we have applied it to our respective branches that we look after as release maintainers :)

Hope that helps?