fix(gateway): secure control and terminal ownership

This commit is contained in:
sechmachine
2026-07-30 11:15:48 +07:00
parent df75b1d250
commit baf4073f68
16 changed files with 488 additions and 36 deletions
+16 -2
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
protocol "git.sechmachine.io.vn/sechmachine/VerseVDI-Protocol/gen/go/protocol"
@@ -110,12 +111,25 @@ func (c *ControlPlaneClient) post(ctx context.Context, path string, payload []by
if c == nil || c.HTTPClient == nil || c.BaseURL == "" {
return nil, errors.New("control-plane client is not configured")
}
request, err := http.NewRequestWithContext(ctx, http.MethodPost, c.BaseURL+path, bytes.NewReader(payload))
baseURL, err := url.Parse(c.BaseURL)
if err != nil || baseURL.Scheme != "https" || baseURL.Host == "" {
return nil, errors.New("control-plane base URL must be absolute HTTPS")
}
requestURL := *baseURL
requestURL.Path = strings.TrimRight(baseURL.Path, "/") + path
requestURL.RawPath = ""
requestURL.RawQuery = ""
requestURL.Fragment = ""
request, err := http.NewRequestWithContext(ctx, http.MethodPost, requestURL.String(), bytes.NewReader(payload))
if err != nil {
return nil, err
}
request.Header.Set("Content-Type", "application/json")
response, err := c.HTTPClient.Do(request)
client := *c.HTTPClient
client.CheckRedirect = func(*http.Request, []*http.Request) error {
return errors.New("control-plane redirects are not permitted")
}
response, err := client.Do(request)
if err != nil {
return nil, err
}