Skip to content

Commit

Permalink
fix: Add x-frame config option (argoproj#4420)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Cizinsky <[email protected]>
  • Loading branch information
LotharKAtt committed Oct 29, 2020
1 parent 46f0ca0 commit 8006da1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/argo/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewServerCommand() *cobra.Command {
enableOpenBrowser bool
eventOperationQueueSize int
eventWorkerCount int
frameOptions string
)

var command = cobra.Command{
Expand Down Expand Up @@ -108,6 +109,7 @@ See %s`, help.ArgoSever),
ConfigName: configMap,
EventOperationQueueSize: eventOperationQueueSize,
EventWorkerCount: eventWorkerCount,
XFrameOptions: frameOptions,
}
browserOpenFunc := func(url string) {}
if enableOpenBrowser {
Expand Down Expand Up @@ -141,5 +143,6 @@ See %s`, help.ArgoSever),
command.Flags().BoolVarP(&enableOpenBrowser, "browser", "b", false, "enable automatic launching of the browser [local mode]")
command.Flags().IntVar(&eventOperationQueueSize, "event-operation-queue-size", 16, "how many events operations that can be queued at once")
command.Flags().IntVar(&eventWorkerCount, "event-worker-count", 4, "how many event workers to run")
command.Flags().StringVar(&frameOptions, "x-frame-options", "DENY", "Set X-Frame-Options header in HTTP responses.")
return &command
}
5 changes: 4 additions & 1 deletion server/apiserver/argoserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type argoServer struct {
stopCh chan struct{}
eventQueueSize int
eventWorkerCount int
xframeOptions string
}

type ArgoServerOpts struct {
Expand All @@ -86,6 +87,7 @@ type ArgoServerOpts struct {
HSTS bool
EventOperationQueueSize int
EventWorkerCount int
XFrameOptions string
}

func NewArgoServer(opts ArgoServerOpts) (*argoServer, error) {
Expand Down Expand Up @@ -122,6 +124,7 @@ func NewArgoServer(opts ArgoServerOpts) (*argoServer, error) {
stopCh: make(chan struct{}),
eventQueueSize: opts.EventOperationQueueSize,
eventWorkerCount: opts.EventWorkerCount,
xframeOptions: opts.XFrameOptions,
}, nil
}

Expand Down Expand Up @@ -288,7 +291,7 @@ func (as *argoServer) newHTTPServer(ctx context.Context, port int, artifactServe
mux.HandleFunc("/oauth2/redirect", as.oAuth2Service.HandleRedirect)
mux.HandleFunc("/oauth2/callback", as.oAuth2Service.HandleCallback)
// we only enable HTST if we are insecure mode, otherwise you would never be able access the UI
mux.HandleFunc("/", static.NewFilesServer(as.baseHRef, as.tlsConfig != nil && as.hsts).ServerFiles)
mux.HandleFunc("/", static.NewFilesServer(as.baseHRef, as.tlsConfig != nil && as.hsts, as.xframeOptions).ServerFiles)
return &httpServer
}

Expand Down
13 changes: 8 additions & 5 deletions server/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
)

type FilesServer struct {
baseHRef string
hsts bool
baseHRef string
hsts bool
xframeOpts string
}

func NewFilesServer(baseHRef string, hsts bool) *FilesServer {
return &FilesServer{baseHRef, hsts}
func NewFilesServer(baseHRef string, hsts bool, xframeOpts string) *FilesServer {
return &FilesServer{baseHRef, hsts, xframeOpts}
}

func (s *FilesServer) ServerFiles(w http.ResponseWriter, r *http.Request) {
Expand All @@ -27,7 +28,9 @@ func (s *FilesServer) ServerFiles(w http.ResponseWriter, r *http.Request) {
w = &responseRewriter{ResponseWriter: w, old: []byte(`<base href="/">`), new: []byte(fmt.Sprintf(`<base href="%s">`, s.baseHRef))}
}

w.Header().Set("X-Frame-Options", "DENY")
if s.xframeOpts != "" {
w.Header().Set("X-Frame-Options", s.xframeOpts)
}
// `data:` is need for Monaco editors wiggly red lines
w.Header().Set("Content-Security-Policy", "default-src 'self' 'unsafe-inline'; img-src 'self' data:")
if s.hsts {
Expand Down

0 comments on commit 8006da1

Please sign in to comment.