Bug 38030

Summary: stocknumberAV.pl fails with CSRF protection
Product: Koha Reporter: Janusz Kaczmarek <januszop>
Component: CatalogingAssignee: Janusz Kaczmarek <januszop>
Status: Needs documenting --- QA Contact: David Cook <dcook>
Severity: normal    
Priority: P5 - low CC: dcook, fridolin.somers, lucas, m.de.rooy, pmis
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38065
Change sponsored?: Sponsored Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00,24.05.06
Circulation function:
Bug Depends on:    
Bug Blocks: 36192    
Attachments: Bug 38030: stocknumberAV.pl fails with CSRF protection
Bug 38030: stocknumberAV.pl fails with CSRF protection
Bug 38030: stocknumberAV.pl fails with CSRF protection
Bug 38030: (QA follow-up) Move csrf_token to POST body from URL

Description Janusz Kaczmarek 2024-09-30 09:20:10 UTC
The value builder stocknumberAV.pl does not work after applying the CSRF protection. In console, it generates entries like:

POST
http://localhost:8081/cgi-bin/koha/cataloguing/plugin_launcher.pl [HTTP/1.1 403 Forbidden 188ms]
Comment 1 Janusz Kaczmarek 2024-09-30 09:45:32 UTC
Created attachment 172216 [details] [review]
Bug 38030: stocknumberAV.pl fails with CSRF protection

The value builder stocknumberAV.pl does not work after applying the CSRF
protection. In console, it generates entries like:

POST
http://localhost:8081/cgi-bin/koha/cataloguing/plugin_launcher.pl
[HTTP/1.1 403 Forbidden 188ms]

Test plan:
==========
1. Modify the MARC bibliographic framework for the default framework by
   choosing stocknumberAV.pl as plugin for subfield 952 $i.
2. In Authorized values, add a new category 'INVENTORY'.  Add a new
   entry there, e.g. 'ABC', with any number in Description (eg. 123).
3. Find any bibliographic record, make sure it uses the default framework.
   If not set the framework accordingly.
4. Edit an item linked to this record.  Go to the 'i - Inventory number'
   subfield.  You should see three dots on the right.  In the input field
   put ABC and click the three dots.
5. Nothing happens.  You can check in the browser console--there should
   be a message like:
   POST http://FQDN:8081/cgi-bin/koha/cataloguing/plugin_launcher.pl
   [HTTP/1.1 403 Forbidden 188ms]
6. Apply the patch; restart_all.  Refresh the browser window.
7. Repeat p. 4.  You should now get the next sequence number next to
   the 'ABC' (i.e. ABC 0000000124 or similar).

Sponsored-by: Ignatianum University in Cracow
Comment 2 Roman Dolny 2024-09-30 20:17:23 UTC
Created attachment 172238 [details] [review]
Bug 38030: stocknumberAV.pl fails with CSRF protection

The value builder stocknumberAV.pl does not work after applying the CSRF
protection. In console, it generates entries like:

POST
http://localhost:8081/cgi-bin/koha/cataloguing/plugin_launcher.pl
[HTTP/1.1 403 Forbidden 188ms]

Test plan:
==========
1. Modify the MARC bibliographic framework for the default framework by
   choosing stocknumberAV.pl as plugin for subfield 952 $i.
2. In Authorized values, add a new category 'INVENTORY'.  Add a new
   entry there, e.g. 'ABC', with any number in Description (eg. 123).
3. Find any bibliographic record, make sure it uses the default framework.
   If not set the framework accordingly.
4. Edit an item linked to this record.  Go to the 'i - Inventory number'
   subfield.  You should see three dots on the right.  In the input field
   put ABC and click the three dots.
5. Nothing happens.  You can check in the browser console--there should
   be a message like:
   POST http://FQDN:8081/cgi-bin/koha/cataloguing/plugin_launcher.pl
   [HTTP/1.1 403 Forbidden 188ms]
6. Apply the patch; restart_all.  Refresh the browser window.
7. Repeat p. 4.  You should now get the next sequence number next to
   the 'ABC' (i.e. ABC 0000000124 or similar).

Sponsored-by: Ignatianum University in Cracow
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Comment 3 David Cook 2024-10-21 03:54:32 UTC
The csrf_token needs to go in the body of the POST and not in the URL. 

If it can't go in the body, then it can go in as a HTTP header.
Comment 4 Marcel de Rooy 2024-10-21 11:51:43 UTC
(In reply to David Cook from comment #3)
> The csrf_token needs to go in the body of the POST and not in the URL. 
> 
> If it can't go in the body, then it can go in as a HTTP header.

Why are we POSTing here ?
Comment 5 Janusz Kaczmarek 2024-10-21 15:58:57 UTC
This particular plugin is changing the content of the database (updating a row in the authorised_values table), if I remember right, so it's OK to POST, IMO.
Comment 6 David Cook 2024-10-22 00:43:16 UTC
Created attachment 173086 [details] [review]
Bug 38030: stocknumberAV.pl fails with CSRF protection

The value builder stocknumberAV.pl does not work after applying the CSRF
protection. In console, it generates entries like:

POST
http://localhost:8081/cgi-bin/koha/cataloguing/plugin_launcher.pl
[HTTP/1.1 403 Forbidden 188ms]

Test plan:
==========
1. Modify the MARC bibliographic framework for the default framework by
   choosing stocknumberAV.pl as plugin for subfield 952 $i.
2. In Authorized values, add a new category 'INVENTORY'.  Add a new
   entry there, e.g. 'ABC', with any number in Description (eg. 123).
3. Find any bibliographic record, make sure it uses the default framework.
   If not set the framework accordingly.
4. Edit an item linked to this record.  Go to the 'i - Inventory number'
   subfield.  You should see three dots on the right.  In the input field
   put ABC and click the three dots.
5. Nothing happens.  You can check in the browser console--there should
   be a message like:
   POST http://FQDN:8081/cgi-bin/koha/cataloguing/plugin_launcher.pl
   [HTTP/1.1 403 Forbidden 188ms]
6. Apply the patch; restart_all.  Refresh the browser window.
7. Repeat p. 4.  You should now get the next sequence number next to
   the 'ABC' (i.e. ABC 0000000124 or similar).

Sponsored-by: Ignatianum University in Cracow
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Comment 7 David Cook 2024-10-22 00:43:18 UTC
Created attachment 173087 [details] [review]
Bug 38030: (QA follow-up) Move csrf_token to POST body from URL

Signed-off-by: David Cook <dcook@prosentient.com.au>
Comment 8 David Cook 2024-10-22 00:44:27 UTC
(In reply to Janusz Kaczmarek from comment #5)
> This particular plugin is changing the content of the database (updating a
> row in the authorised_values table), if I remember right, so it's OK to
> POST, IMO.

That's true
Comment 9 Katrin Fischer 2024-10-22 10:10:03 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 10 Lucas Gass (lukeg) 2024-11-20 17:36:16 UTC
I don't see the follow up commit in main. Am I missing something?
Comment 11 Janusz Kaczmarek 2024-11-20 17:57:38 UTC
(In reply to Lucas Gass (lukeg) from comment #10)
> I don't see the follow up commit in main. Am I missing something?

Indeed.  Me neither.  @Katrin, would you be able to double check it?
Comment 12 Katrin Fischer 2024-11-21 12:31:24 UTC
Picked the follow-up for main. Thanks!
Comment 13 Lucas Gass (lukeg) 2024-11-21 14:36:53 UTC
Backported to 24.05.x for upcoming 24.05.06
Comment 14 Fridolin Somers 2024-12-13 15:19:23 UTC
Not for 23.11.x