tgswitch icon indicating copy to clipboard operation
tgswitch copied to clipboard

Inferring version from `terragrunt_version_constraint` installs an HTML 404 page as an executable

Open josh-wolfe-okcupid opened this issue 3 months ago • 0 comments

josh@josh-laptop:~/tmp$ mkdir empty
josh@josh-laptop:~/tmp$ cd empty
josh@josh-laptop:~/tmp/empty$ cat ~/.tgswitch.toml 
bin = "/home/josh/.terragrunt.versions/terragrunt"
josh@josh-laptop:~/tmp/empty$ tgswitch --version

Version: 0.6.0
josh@josh-laptop:~/tmp/empty$ rm ~/.terragrunt.versions/terragrunt_*
josh@josh-laptop:~/tmp/empty$ echo 'terragrunt_version_constraint = "=0.38.12"' > terragrunt.hcl
josh@josh-laptop:~/tmp/empty$ tgswitch 
Reading configuration from home directory for .tgswitch.toml
Terragrunt file found: /home/josh/tmp/empty/terragrunt.hcl
Reading required version from constraint: =0.38.12
Matched version: 0.38.12
Downloading https://warrensbox.github.io/terragunt-versions-list/index.json/v0.38.12/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
9379 bytes downloaded.
Switched terragrunt to version "0.38.12" 
josh@josh-laptop:~/tmp/empty$ head `which terragrunt`
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'">
    <title>Page not found &middot; GitHub Pages</title>
    <style type="text/css" media="screen">
      body {
        background-color: #f1f1f1;
        margin: 0;
josh@josh-laptop:~/tmp/empty$ terragrunt --version
/home/josh/.terragrunt.versions/terragrunt: line 1: syntax error near unexpected token `newline'
/home/josh/.terragrunt.versions/terragrunt: line 1: `<!DOCTYPE html>'

I probably don't need to explain how hazardous and dangerous this is.

Perhaps there's missing error checking on the HTTP status code? Also, when I tgswitch 0.38.12 explicitly, everything works, so it seems there's a bug specifically in the terragrunt_version_constraint inference path.

josh-wolfe-okcupid avatar Apr 25 '24 20:04 josh-wolfe-okcupid