Skip to content

Commit 46e6fa2

Browse files
committed
basic fixes
1 parent 5644f75 commit 46e6fa2

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func Run(ctx context.Context, config Config, args []string) error {
186186
cmd.Stdin = os.Stdin
187187

188188
logger.Debug("Executing command in boundary", "command", strings.Join(args, " "))
189-
err := boundaryInstance.Command(args).Run()
189+
err := cmd.Run()
190190
if err != nil {
191191
logger.Error("Command execution failed", "error", err)
192192
}

jail/unprivileged.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jail
22

33
import (
4+
"fmt"
45
"log/slog"
56
"os/exec"
67
)
@@ -34,9 +35,11 @@ func (u *Unprivileged) Start() error {
3435
u.logger.Debug("Starting in unprivileged mode")
3536
e := getEnvs(u.configDir, u.caCertPath)
3637
u.commandEnv = mergeEnvs(e, map[string]string{
37-
"HOME": u.homeDir,
38-
"USER": u.username,
39-
"LOGNAME": u.username,
38+
"HOME": u.homeDir,
39+
"USER": u.username,
40+
"LOGNAME": u.username,
41+
"HTTP_PROXY": fmt.Sprintf("http://localhost:%d", u.httpProxyPort),
42+
"HTTPS_PROXY": fmt.Sprintf("https://localhost:%d", u.httpProxyPort),
4043
})
4144
return nil
4245
}
@@ -53,4 +56,4 @@ func (u *Unprivileged) Command(command []string) *exec.Cmd {
5356
func (u *Unprivileged) Close() error {
5457
u.logger.Debug("Closing unprivileged jail")
5558
return nil
56-
}
59+
}

proxy/proxy.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,20 @@ func (p *Server) handleHTTP(w http.ResponseWriter, r *http.Request) {
133133
}
134134

135135
// Forward regular HTTP request
136-
p.forwardHTTPRequest(w, r)
136+
p.forwardRequest(w, r, false)
137137
}
138138

139-
// forwardHTTPRequest forwards a regular HTTP request
140-
func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
139+
// forwardRequest forwards a regular HTTP request
140+
func (p *Server) forwardRequest(w http.ResponseWriter, r *http.Request, https bool) {
141141
p.logger.Debug("forwardHTTPRequest called", "method", r.Method, "url", r.URL.String(), "host", r.Host)
142142

143+
s := "http"
144+
if https {
145+
s = "https"
146+
}
143147
// Create a new request to the target server
144148
targetURL := &url.URL{
145-
Scheme: "http",
149+
Scheme: s,
146150
Host: r.Host,
147151
Path: r.URL.Path,
148152
RawQuery: r.URL.RawQuery,
@@ -357,13 +361,21 @@ func (p *Server) handleTLSConnection(tlsConn *tls.Conn, hostname string) {
357361

358362
// handleDecryptedHTTPS handles decrypted HTTPS requests and applies rules
359363
func (p *Server) handleDecryptedHTTPS(w http.ResponseWriter, r *http.Request) {
364+
fullURL := r.URL.String()
365+
if r.URL.Host == "" {
366+
// Fallback: construct URL from Host header
367+
fullURL = fmt.Sprintf("https://%s%s", r.Host, r.URL.Path)
368+
if r.URL.RawQuery != "" {
369+
fullURL += "?" + r.URL.RawQuery
370+
}
371+
}
360372
// Check if request should be allowed
361-
result := p.ruleEngine.Evaluate(r.Method, r.URL.String())
373+
result := p.ruleEngine.Evaluate(r.Method, fullURL)
362374

363375
// Audit the request
364376
p.auditor.AuditRequest(audit.Request{
365377
Method: r.Method,
366-
URL: r.URL.String(),
378+
URL: fullURL,
367379
Allowed: result.Allowed,
368380
Rule: result.Rule,
369381
})
@@ -374,7 +386,7 @@ func (p *Server) handleDecryptedHTTPS(w http.ResponseWriter, r *http.Request) {
374386
}
375387

376388
// Forward the HTTPS request (now handled same as HTTP after TLS termination)
377-
p.forwardHTTPRequest(w, r)
389+
p.forwardRequest(w, r, true)
378390
}
379391

380392
// handleConnectionWithTLSDetection detects TLS vs HTTP and handles appropriately

0 commit comments

Comments
 (0)