Skip to content

Commit 23fb954

Browse files
fix: code review findings — URL validation hardening, error sanitization, screenshot parse error
1 parent 487914d commit 23fb954

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

internal/client/browser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ func (c *Client) Navigate(tabID, url string) error {
9292
return err
9393
}
9494

95-
var blockedURLSchemes = []string{"file:", "javascript:", "data:", "vbscript:"}
95+
var blockedURLSchemes = []string{"file:", "javascript:", "data:", "vbscript:", "about:", "chrome:", "edge:"}
9696

9797
func validateURL(rawURL string) error {
98-
lower := strings.ToLower(rawURL)
98+
lower := strings.ToLower(strings.TrimSpace(rawURL))
9999
for _, scheme := range blockedURLSchemes {
100100
if strings.HasPrefix(lower, scheme) {
101101
return fmt.Errorf("blocked URL scheme %q", scheme)
@@ -333,7 +333,7 @@ func (c *Client) Screenshot(tabID string, fullPage bool) (string, error) {
333333
Data string `json:"data"`
334334
}
335335
if err := json.Unmarshal(raw, &result); err != nil {
336-
return string(raw), nil
336+
return "", fmt.Errorf("parse screenshot response: %w", err)
337337
}
338338
return result.Data, nil
339339
}

internal/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (c *Client) SendRequest(method string, params map[string]interface{}) (json
209209
select {
210210
case resp := <-ch:
211211
if resp.Error != nil {
212-
return nil, fmt.Errorf("rpc error in %s: %s", method, resp.Error.Message)
212+
return nil, fmt.Errorf("rpc error in %s: %s", method, resp.Error.Error())
213213
}
214214
return resp.Result, nil
215215
case <-c.ctx.Done():

0 commit comments

Comments
 (0)