@@ -23,6 +23,7 @@ import (
2323 "net/http/cgi"
2424 "path"
2525 "path/filepath"
26+ "strings"
2627
2728 "github.com/mholt/caddy/caddyhttp/httpserver"
2829)
@@ -62,7 +63,7 @@ func currentDir() (wdStr string) {
6263// setupCall instantiates a CGI handler based on the incoming request and the
6364// configuration rule that it matches.
6465func setupCall (h handlerType , rule ruleType , lfStr , rtStr string ,
65- rep httpserver.Replacer , username string ) (cgiHnd cgi.Handler ) {
66+ rep httpserver.Replacer , hdr http. Header , username string ) (cgiHnd cgi.Handler ) {
6667 cgiHnd .Root = "/"
6768 cgiHnd .Dir = h .root
6869 rep .Set ("root" , h .root )
@@ -86,6 +87,13 @@ func setupCall(h handlerType, rule ruleType, lfStr, rtStr string,
8687 envAdd ("PATH_INFO" , rtStr )
8788 envAdd ("SCRIPT_FILENAME" , cgiHnd .Path )
8889 envAdd ("SCRIPT_NAME" , lfStr )
90+ // Convey JSON Web Token claims to CGI app by means of environment
91+ for key , list := range hdr {
92+ if strings .HasPrefix (key , "Token-Claim-" ) {
93+ cgiHnd .Env = append (cgiHnd .Env , strings .ToUpper (key )+ "=" +
94+ strings .Join (list , "\t " ))
95+ }
96+ }
8997 cgiHnd .InheritEnv = append (cgiHnd .InheritEnv , rule .passEnvs ... )
9098 cgiHnd .InheritEnv = append (cgiHnd .InheritEnv , rule .passEnvs ... )
9199 for _ , str := range rule .args {
@@ -106,7 +114,7 @@ func (h handlerType) ServeHTTP(w http.ResponseWriter, r *http.Request) (code int
106114 // Retrieve name of remote user that was set by some downstream middleware,
107115 // possibly basicauth.
108116 remoteUser , _ := r .Context ().Value (httpserver .RemoteUserCtxKey ).(string ) // Blank if not set
109- cgiHnd := setupCall (h , rule , lfStr , rtStr , rep , remoteUser )
117+ cgiHnd := setupCall (h , rule , lfStr , rtStr , rep , r . Header , remoteUser )
110118 cgiHnd .Stderr = & buf
111119 cgiHnd .ServeHTTP (w , r )
112120 if buf .Len () > 0 {
0 commit comments