Bug 37553

Summary: Fix CSRF handling in koha-svc.pl script
Product: Koha Reporter: David Cook <dcook>
Component: Command-line UtilitiesAssignee: David Cook <dcook>
Status: Needs documenting --- QA Contact: Marcel de Rooy <m.de.rooy>
Severity: minor    
Priority: P5 - low CC: fridolin.somers, lucas, m.de.rooy, robin
Version: Main   
Hardware: All   
OS: All   
Change 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.04
Circulation function:
Bug Depends on:    
Bug Blocks: 36192    
Attachments: Bug 37553: Use CSRF token for authenicated session for POSTing
Bug 37553: Consistently send Csrf-Token in request header
Bug 37553: Tidy to make QA tools happy
Bug 37553: Use CSRF token for authenicated session for POSTing
Bug 37553: Consistently send Csrf-Token in request header
Bug 37553: Tidy to make QA tools happy
Bug 37553: Use CSRF token for authenicated session for POSTing
Bug 37553: Consistently send Csrf-Token in request header
Bug 37553: Tidy to make QA tools happy

Description David Cook 2024-08-02 01:34:33 UTC
./misc/migration_tools/koha-svc.pl is broken again, as I think we fixed some other CSRF internals after we fixed koha-svc.pl last. Anyway, it should be an easy fix!
Comment 1 David Cook 2024-08-02 01:39:39 UTC
Created attachment 169968 [details] [review]
Bug 37553: Use CSRF token for authenicated session for POSTing

This change fixes the Koha::SVC to store the CSRF token for
the authenticated session for further POSTing.

Test plan:
0. Apply the patch
1. perl ./misc/migration_tools/koha-svc.pl \
    http://localhost:8081/cgi-bin/koha/svc koha koha 29 > bib-29.xml
2. perl ./misc/migration_tools/koha-svc.pl \
    http://localhost:8081/cgi-bin/koha/svc koha koha 29 bib-29.xml
3. Note that the following appears in STDOUT and there is no 403 error:
"update 29 from bib-29.xml"
Comment 2 David Cook 2024-08-02 01:50:10 UTC
Created attachment 169974 [details] [review]
Bug 37553: Consistently send Csrf-Token in request header

This change consistently sends the Csrf-Token in the request header.
Previously, one POST sent it in the request body, while the other POST
sent it in the request header. Since we're using an API, it's best
for us to always send it in the request header

Test plan:
0. Apply the patch
1. perl ./misc/migration_tools/koha-svc.pl \
	http://localhost:8081/cgi-bin/koha/svc koha koha 29 > bib-29.xml
2. perl ./misc/migration_tools/koha-svc.pl \
	http://localhost:8081/cgi-bin/koha/svc koha koha 29 bib-29.xml
3. Note that the following appears in STDOUT and there is no 403 error:
"update 29 from bib-29.xml"
Comment 3 David Cook 2024-08-02 02:03:39 UTC
Created attachment 169976 [details] [review]
Bug 37553: Tidy to make QA tools happy
Comment 4 David Nind 2024-08-02 03:29:43 UTC
Created attachment 169977 [details] [review]
Bug 37553: Use CSRF token for authenicated session for POSTing

This change fixes the Koha::SVC to store the CSRF token for
the authenticated session for further POSTing.

Test plan:
0. Apply the patch
1. perl ./misc/migration_tools/koha-svc.pl \
    http://localhost:8081/cgi-bin/koha/svc koha koha 29 > bib-29.xml
2. perl ./misc/migration_tools/koha-svc.pl \
    http://localhost:8081/cgi-bin/koha/svc koha koha 29 bib-29.xml
3. Note that the following appears in STDOUT and there is no 403 error:
"update 29 from bib-29.xml"

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 David Nind 2024-08-02 03:29:45 UTC
Created attachment 169978 [details] [review]
Bug 37553: Consistently send Csrf-Token in request header

This change consistently sends the Csrf-Token in the request header.
Previously, one POST sent it in the request body, while the other POST
sent it in the request header. Since we're using an API, it's best
for us to always send it in the request header

Test plan:
0. Apply the patch
1. perl ./misc/migration_tools/koha-svc.pl \
	http://localhost:8081/cgi-bin/koha/svc koha koha 29 > bib-29.xml
2. perl ./misc/migration_tools/koha-svc.pl \
	http://localhost:8081/cgi-bin/koha/svc koha koha 29 bib-29.xml
3. Note that the following appears in STDOUT and there is no 403 error:
"update 29 from bib-29.xml"

Signed-off-by: David Nind <david@davidnind.com>
Comment 6 David Nind 2024-08-02 03:29:48 UTC
Created attachment 169979 [details] [review]
Bug 37553: Tidy to make QA tools happy

Signed-off-by: David Nind <david@davidnind.com>
Comment 7 Marcel de Rooy 2024-08-02 06:35:14 UTC
Created attachment 169980 [details] [review]
Bug 37553: Use CSRF token for authenicated session for POSTing

This change fixes the Koha::SVC to store the CSRF token for
the authenticated session for further POSTing.

Test plan:
0. Apply the patch
1. perl ./misc/migration_tools/koha-svc.pl \
    http://localhost:8081/cgi-bin/koha/svc koha koha 29 > bib-29.xml
2. perl ./misc/migration_tools/koha-svc.pl \
    http://localhost:8081/cgi-bin/koha/svc koha koha 29 bib-29.xml
3. Note that the following appears in STDOUT and there is no 403 error:
"update 29 from bib-29.xml"

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 8 Marcel de Rooy 2024-08-02 06:35:17 UTC
Created attachment 169981 [details] [review]
Bug 37553: Consistently send Csrf-Token in request header

This change consistently sends the Csrf-Token in the request header.
Previously, one POST sent it in the request body, while the other POST
sent it in the request header. Since we're using an API, it's best
for us to always send it in the request header

Test plan:
0. Apply the patch
1. perl ./misc/migration_tools/koha-svc.pl \
	http://localhost:8081/cgi-bin/koha/svc koha koha 29 > bib-29.xml
2. perl ./misc/migration_tools/koha-svc.pl \
	http://localhost:8081/cgi-bin/koha/svc koha koha 29 bib-29.xml
3. Note that the following appears in STDOUT and there is no 403 error:
"update 29 from bib-29.xml"

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 9 Marcel de Rooy 2024-08-02 06:35:19 UTC
Created attachment 169982 [details] [review]
Bug 37553: Tidy to make QA tools happy

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 10 Katrin Fischer 2024-08-02 17:01:46 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 11 Lucas Gass (lukeg) 2024-09-11 15:54:17 UTC
Backported to 24.05.x for upcoming 24.05.04
Comment 12 Fridolin Somers 2024-09-25 08:33:23 UTC
Not for 23.11.x