orbital-sync icon indicating copy to clipboard operation
orbital-sync copied to clipboard

Fix error "Not authorized" when uploading archives

Open Hazegard opened this issue 1 year ago • 1 comments

The persistentlogin=off snippet in the request makes the server to respond the cookie persistentlogin, which will then be send in the POST teleporter.php request when uploading backup, which will cause the pihole server to respond: "Not authorized" when this cookie is sent.

Removing this snippet in the login request removes the persistentlogin in the response. Conesquently, the archive upload is accepted by the pihole sever.

=====

When using orbital-sync, I have the following logs:

pihole-sync  | 6/30/2024, 8:58:04 AM: ➡️   Signing in to https://example.com/admin...
 ihole-sync  | 6/30/2024, 8:58:04 AM: ✔️   Successfully signed in to https://example.com/admin!
 ihole-sync  | 6/30/2024, 8:58:04 AM: ➡️   Downloading backup from https://example.com/admin...
 ihole-sync  | 6/30/2024, 8:58:04 AM: ✔️   Backup from https://example.com/admin completed!
 ihole-sync  | 6/30/2024, 8:58:04 AM: ➡️   Signing in to https://example.com/admin...
 ihole-sync  | 6/30/2024, 8:58:04 AM: ➡️   Signing in to https://example.com/admin...
 ihole-sync  | 6/30/2024, 8:58:04 AM: ➡️   Signing in to https://example.com/admin...
 ihole-sync  | 6/30/2024, 8:58:04 AM: ✔️   Successfully signed in to https://example.com/admin!
 ihole-sync  | 6/30/2024, 8:58:04 AM: ➡️   Uploading backup to https://example.com/admin...
 ihole-sync  | 6/30/2024, 8:58:04 AM: {"host":"https://example.com","path":"/admin","status":200,"responseBody":"Not authorized"}
pihole-sync  | 6/30/2024, 8:58:04 AM: ⚠ Error: Failed to upload backup to "https://example.com/admin".
pihole-sync  | 6/30/2024, 8:58:04 AM: ✔️   Successfully signed in to https://example.com/admin!
 ihole-sync  | 6/30/2024, 8:58:04 AM: ➡️   Uploading backup to https://example.com/admin...
 ihole-sync  | 6/30/2024, 8:58:04 AM: {"host":"https://example.com","path":"/admin","status":200,"responseBody":"Not authorized"}
pihole-sync  | 6/30/2024, 8:58:04 AM: ⚠ Error: Failed to upload backup to "https://example.com/admin".
pihole-sync  | 6/30/2024, 8:58:04 AM: ✔️   Successfully signed in to https://example.com/admin!
 ihole-sync  | 6/30/2024, 8:58:04 AM: ➡️   Uploading backup to https://example.com/admin...
 ihole-sync  | 6/30/2024, 8:58:04 AM: {"host":"https://example.com","path":"/admin","status":200,"responseBody":"Not authorized"}
pihole-sync  | 6/30/2024, 8:58:04 AM: ⚠ Error: Failed to upload backup to "https://example.com/admin".
pihole-sync  | 6/30/2024, 8:58:04 AM: ⚠ Failure: 0/3 hosts synced.
pihole-sync  | 6/30/2024, 8:58:04 AM: Waiting 1 minutes...
pihole-sync  | 6/30/2024, 8:59:04 AM: ➡️   Signing in to https://example.com/admin!
pihole-sync  | 6/30/2024, 8:59:04 AM: ➡️   Uploading backup to https://example.com/admin!
pihole-sync  | 6/30/2024, 8:59:04 AM: ➡️   Uploading backup to https://example.com","path":"/admin","status":200,"responseBody":"Not authorized"}
pihole-sync  | 6/30/2024, 8:59:04 AM: ⚠ Error: Failed to upload backup to "https://example.com/admin".
pihole-sync  | 6/30/2024, 8:59:04 AM: {"host":"https://example.com","path":"/admin","status":200,"responseBody":"Not authorized"}
pihole-sync  | 6/30/2024, 8:59:04 AM: ⚠ Error: Failed to upload backup to "https://example.com/admin".
pihole-sync  | 6/30/2024, 8:59:05 AM: ✔️"  Successfully signed in to https://example.com/admin!
pihole-sync  | 6/30/2024, 8:59:05 AM: ➡️"  Uploading backup to https://example.com","path":"/admin","status":200,"responseBody":"Not authorized"}
pihole-sync  | 6/30/2024, 8:59:05 AM: ⚠ Error: Failed to upload backup to "https://example.com/admin".
pihole-sync  | 6/30/2024, 8:59:05 AM: ⚠ Failure: 0/3 hosts synced.
pihole-sync  | 6/30/2024, 8:59:05 AM: Waiting 1 minutes...

I tracked the upload failure, and it is related to the persistentlogin cookie being sent with the upload request:

image

When I try the same request without this cookie, the upload works:

image

This cookie comes from the &persistentlogin=off part of the request sent during the login (https://github.com/mattwebbio/orbital-sync/blob/master/src/client/v5/index.ts#L42)

When this part is appended to the request, the persistentlogin cookie is received (and is then sent during the backup upload request):

image

When i remove this part, the cookie is not set and the upload works: image

Hazegard avatar Jun 30 '24 12:06 Hazegard

This is amazing! Thanks so much for figuring this out :)

mattwebbio avatar Jul 01 '24 18:07 mattwebbio

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.52%. Comparing base (103155c) to head (c9eea45).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #359   +/-   ##
=======================================
  Coverage   97.52%   97.52%           
=======================================
  Files          10       10           
  Lines         283      283           
  Branches       95       97    +2     
=======================================
  Hits          276      276           
  Misses          5        5           
  Partials        2        2           
Flag Coverage Δ
integration 52.96% <ø> (ø)
unit 96.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 05 '24 16:08 codecov[bot]