CVE-2022-29164: Insufficient Information (NVD-CWE-noinfo)
value: Argo Workflows is an open source container-native workflow engine for orchestrating parallel jobs on Kubernetes. In affected versions an attacker can create a workflow which produces a HTML artifact containing an HTML file that contains a script which uses XHR calls to interact with the Argo Server API. The attacker emails the deep-link to the artifact to their victim. The victim opens the link, the script starts running. As the script has access to the Argo Server API (as the victim), so may read information about the victim’s workflows, or create and delete workflows. Note the attacker must be an insider: they must have access to the same cluster as the victim and must already be able to run their own workflows. The attacker must have an understanding of the victim’s system. We have seen no evidence of this in the wild. We urge all users to upgrade to the fixed versions.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
CVSS v3 base score: 7.1
Published: 2022-05-06T00:15Z
Repository: https://github.com/argoproj/argo-workflows
Language: Go
Files changed: server/apiserver/argoserver.go, server/artifacts/artifact_server.go, test/e2e/argo_server_test.go
Commit date: 2022-05-03 17:52:48 +0000
Commit message: fix: Added artifact Content-Security-Policy (#8585)

Signed-off-by: Alex Collins <alex_collins@intuit.com>
Diff: diff --git a/server/apiserver/argoserver.go b/server/apiserver/argoserver.go
index 322df92e..49e4d7cc 100644
--- a/server/apiserver/argoserver.go
+++ b/server/apiserver/argoserver.go
@@ -339,15 +339,19 @@ func (as *argoServer) newHTTPServer(ctx context.Context, port int, artifactServe
 	mux.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
 		// we must delete this header for API request to prevent "stream terminated by RST_STREAM with error code: PROTOCOL_ERROR" error
 		r.Header.Del("Connection")
 		webhookInterceptor(w, r, gwmux)
 	})
-	mux.HandleFunc("/artifacts/", artifactServer.GetOutputArtifact)
-	mux.HandleFunc("/input-artifacts/", artifactServer.GetInputArtifact)
-	mux.HandleFunc("/artifacts-by-uid/", artifactServer.GetOutputArtifactByUID)
-	mux.HandleFunc("/input-artifacts-by-uid/", artifactServer.GetInputArtifactByUID)
-	mux.HandleFunc("/artifact-files/", artifactServer.GetArtifactFile)
+
+	// emergency environment variable that allows you to disable the artifact service in case of problems
+	if os.Getenv("ARGO_ARTIFACT_SERVER") != "false" {
+		mux.HandleFunc("/artifacts/", artifactServer.GetOutputArtifact)
+		mux.HandleFunc("/input-artifacts/", artifactServer.GetInputArtifact)
+		mux.HandleFunc("/artifacts-by-uid/", artifactServer.GetOutputArtifactByUID)
+		mux.HandleFunc("/input-artifacts-by-uid/", artifactServer.GetInputArtifactByUID)
+		mux.HandleFunc("/artifact-files/", artifactServer.GetArtifactFile)
+	}
 	mux.Handle("/oauth2/redirect", handlers.ProxyHeaders(http.HandlerFunc(as.oAuth2Service.HandleRedirect)))
 	mux.Handle("/oauth2/callback", handlers.ProxyHeaders(http.HandlerFunc(as.oAuth2Service.HandleCallback)))
 	mux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
 		if os.Getenv("ARGO_SERVER_METRICS_AUTH") != "false" {
 			header := metadata.New(map[string]string{"authorization": r.Header.Get("Authorization")})
diff --git a/server/artifacts/artifact_server.go b/server/artifacts/artifact_server.go
index 995aef7d..57770692 100644
--- a/server/artifacts/artifact_server.go
+++ b/server/artifacts/artifact_server.go
@@ -14,10 +14,11 @@ import (
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/metadata"
 	"google.golang.org/grpc/status"
 	apierr "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/utils/env"
 
 	"github.com/argoproj/argo-workflows/v3/persist/sqldb"
 	wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
 	"github.com/argoproj/argo-workflows/v3/server/auth"
 	"github.com/argoproj/argo-workflows/v3/server/types"
@@ -407,10 +408,12 @@ func (a *ArtifactServer) returnArtifact(w http.ResponseWriter, art *wfv1.Artifac
 	}()
 
 	key, _ := art.GetKey()
 	w.Header().Add("Content-Disposition", fmt.Sprintf(`filename="%s"`, path.Base(key)))
 	w.Header().Add("Content-Type", mime.TypeByExtension(path.Ext(key)))
+	w.Header().Add("Content-Security-Policy", env.GetString("ARGO_ARTIFACT_CONTENT_SECURITY_POLICY", "sandbox; base-uri 'none'; default-src 'none'; img-src 'self'; style-src 'self'"))
+	w.Header().Add("X-Frame-Options", env.GetString("ARGO_ARTIFACT_X_FRAME_OPTIONS", "SAMEORIGIN"))
 
 	_, err = io.Copy(w, stream)
 	if err != nil {
 		http.Error(w, fmt.Sprintf("failed to stream artifact: %v", err), http.StatusInternalServerError)
 	} else {
diff --git a/test/e2e/argo_server_test.go b/test/e2e/argo_server_test.go
index d936942f..c972b1bf 100644
--- a/test/e2e/argo_server_test.go
+++ b/test/e2e/argo_server_test.go
@@ -1063,10 +1063,15 @@ func (s *ArgoServerSuite) TestArtifactServer() {
 			Status(200)
 
 		resp.Body().
 			Contains(":) Hello Argo!")
 
+		resp.Header("Content-Security-Policy").
+			Equal("sandbox; base-uri 'none'; default-src 'none'; img-src 'self'; style-src 'self'") // MSB
+
+		resp.Header("X-Frame-Options").
+			Equal("SAMEORIGIN")
 	})
 
 	// In this case, the artifact name is a file
 	s.Run("GetArtifactFile", func() {
 		resp := s.e().GET("/artifact-files/argo/workflows/" + name + "/" + name + "/outputs/main-file").
@@ -1074,10 +1079,15 @@ func (s *ArgoServerSuite) TestArtifactServer() {
 			Status(200)
 
 		resp.Body().
 			Contains(":) Hello Argo!")
 
+		resp.Header("Content-Security-Policy").
+			Equal("sandbox; base-uri 'none'; default-src 'none'; img-src 'self'; style-src 'self'") // MSB
+
+		resp.Header("X-Frame-Options").
+			Equal("SAMEORIGIN")
 	})
 
 	// In this case, the artifact name is a directory
 	s.Run("GetArtifactFileDirectory", func() {
 		resp := s.e().GET("/artifact-files/argo/workflows/" + name + "/" + name + "/outputs/out/").
@@ -1108,10 +1118,15 @@ func (s *ArgoServerSuite) TestArtifactServer() {
 			Status(200)
 
 		resp.Body().
 			Contains(":) Hello Argo!")
 
+		resp.Header("Content-Security-Policy").
+			Equal("sandbox; base-uri 'none'; default-src 'none'; img-src 'self'; style-src 'self'") // MSB
+
+		resp.Header("X-Frame-Options").
+			Equal("SAMEORIGIN")
 	})
 
 	// In this case, the artifact name is a file
 	s.Run("GetArtifactBadFile", func() {
 		_ = s.e().GET("/artifact-files/argo/workflows/" + name + "/" + name + "/outputs/not-a-file").

Vulnerable code: 	mux.HandleFunc("/artifacts/", artifactServer.GetOutputArtifact)
	mux.HandleFunc("/input-artifacts/", artifactServer.GetInputArtifact)
	mux.HandleFunc("/artifacts-by-uid/", artifactServer.GetOutputArtifactByUID)
	mux.HandleFunc("/input-artifacts-by-uid/", artifactServer.GetInputArtifactByUID)
	mux.HandleFunc("/artifact-files/", artifactServer.GetArtifactFile)
Fixed code: 
	// emergency environment variable that allows you to disable the artifact service in case of problems
	if os.Getenv("ARGO_ARTIFACT_SERVER") != "false" {
		mux.HandleFunc("/artifacts/", artifactServer.GetOutputArtifact)
		mux.HandleFunc("/input-artifacts/", artifactServer.GetInputArtifact)
		mux.HandleFunc("/artifacts-by-uid/", artifactServer.GetOutputArtifactByUID)
		mux.HandleFunc("/input-artifacts-by-uid/", artifactServer.GetInputArtifactByUID)
		mux.HandleFunc("/artifact-files/", artifactServer.GetArtifactFile)
	}
	"k8s.io/utils/env"
	w.Header().Add("Content-Security-Policy", env.GetString("ARGO_ARTIFACT_CONTENT_SECURITY_POLICY", "sandbox; base-uri 'none'; default-src 'none'; img-src 'self'; style-src 'self'"))
	w.Header().Add("X-Frame-Options", env.GetString("ARGO_ARTIFACT_X_FRAME_OPTIONS", "SAMEORIGIN"))
		resp.Header("Content-Security-Policy").
			Equal("sandbox; base-uri 'none'; default-src 'none'; img-src 'self'; style-src 'self'") // MSB

		resp.Header("X-Frame-Options").
			Equal("SAMEORIGIN")
		resp.Header("Content-Security-Policy").
			Equal("sandbox; base-uri 'none'; default-src 'none'; img-src 'self'; style-src 'self'") // MSB

		resp.Header("X-Frame-Options").
			Equal("SAMEORIGIN")
		resp.Header("Content-Security-Policy").
			Equal("sandbox; base-uri 'none'; default-src 'none'; img-src 'self'; style-src 'self'") // MSB

		resp.Header("X-Frame-Options").
			Equal("SAMEORIGIN")