server icon indicating copy to clipboard operation
server copied to clipboard

update process breaks working installations if downloaded files are corrupted

Open w4rs3n opened this issue 3 years ago • 6 comments

Steps To Reproduce

  1. run bitwarden.sh updateself
  2. run bitwarden.sh update
  3. check the content of bwdata/scripts/run.sh

Expected Result

The appication should update itself or at least not break if the update fails.

Actual Result

The update process breaks the installation because neither the integrity of the downloaded file nor the general success of the download are being verified.

Screenshots or Videos

No response

Additional Context

Currently the API at https://func.bitwarden.com/api/dl/?app=self-host&platform=linux&variant=run returns an HTTP 500 response with a JSON error:

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
   at AppFunctions.Downloads.GetToolsDownloadUrlAsync(String repository, String filename) in /home/runner/work/misc/misc/AzureFunctions/prod/AppFunctions/Downloads.cs:line 240
   at AppFunctions.Downloads.GetDownloadUrlAsync(ValueTuple`4 valueTuple) in /home/runner/work/misc/misc/AzureFunctions/prod/AppFunctions/Downloads.cs:line 197
   at AppFunctions.Downloads.Run(HttpRequest req, ILogger log) in /home/runner/work/misc/misc/AzureFunctions/prod/AppFunctions/Downloads.cs:line 174

The downloadRunFile function in bitwarden.sh downloads the run.sh file directly to the script directory, overwriting any existing file. In this case, it downloads the error message and saves it as run.sh.
I would suggest downloading the file to a temporary location, checking the HTTP return code and/or the return code of curl and only moving it to the actual location on a successful request. An additional checksum comparison could also be made.

Build Version

bitwarden.sh version 2023.1.0

Environment

Self-Hosted

Environment Details

  • Operating system: Debian 11
  • Environment: Docker
  • Hardware: QEMU VM with 2 vCPUs & 8G RAM

Issue Tracking Info

  • [X] I understand that work is tracked outside of Github. A PR will be linked to this issue should one be opened to address it, but Bitwarden doesn't use fields like "assigned", "milestone", or "project" to track progress.

w4rs3n avatar Jan 28 '23 02:01 w4rs3n

Also hitting this issue today. Thanks for creating the bug report

chriscareycode avatar Jan 28 '23 04:01 chriscareycode

Same Issue after ./bitwarden.sh updateconf Issue is gone.

jonathan-martz avatar Jan 28 '23 18:01 jonathan-martz

Hi @davidwinterstein this issue appears to be a duplicate of this one: https://github.com/bitwarden/self-host/issues/78 can you confirm if you are also able to update your instance now?

Greenderella avatar Jan 30 '23 09:01 Greenderella

Hey there, sorry about the late reply. I somehow didn't get notified and just saw the responses when checking because a failed update broke my instance again.

Regarding the duplicate:
Well, this report was created first. 😇
But I guess in the wrong repository? Sorry about that.

Yes, the problem was fixed when the API worked again.

The addition to the downloadRunFile function that checks the HTTP return code still breaks instances on failure, because it still downloads directly to the "final" destination of run.sh instead of downloading to a temporary location and only moving the file on success.
In the case I just experienced, the API sent an HTTP 400 response upon executing bitwarden.sh update, resulting in the following message:

Unable to download run script from https://func.bitwarden.com/api/dl/?app=self-host&platform=linux&variant=run. Received status code: 400 http response: {"message": "Traffic from your network looks unusual. Connect to a different network or try again later. [Error Code 2]"}

The run.sh file was missing afterwards since the function removes it on failure.

Regarding the error message:
I am automatically updating the instance via cron every 2 hours. Is that too often so I ran into some kind of rate limiting? Or what could be the reason for the "Traffic from your network looks unusual" message?

w4rs3n avatar Feb 20 '23 18:02 w4rs3n

This behavior is still active and will reoccur whenever the request from the update process fails.
My other issue at bitwarden/self-host#82 was closed with the notice "This isn't a bug, but a security measure on our end".
I would not classify a failed update process resulting in a broken installation a security measure.
Do you have any further details perhaps @Greenderella?

w4rs3n avatar Mar 15 '23 15:03 w4rs3n

This behaviour is still active currently - https://func.bitwarden.com/ - Currently "This function host is not running." Trying to update BitWarden using the ./bitwarden.sh updateself causes the file to get replaced with that line.

JasmeowTheCat avatar Jun 12 '24 18:06 JasmeowTheCat