Skip to content

Commit dbc5a0a

Browse files
committed
review: update security for private_key file
1 parent df74439 commit dbc5a0a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

pkg/extensions/webbotauth.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
const (
2121
defaultLocalhostURL = "http://localhost:8000"
2222
defaultDirMode = 0755
23+
defaultFileMode = 0644
2324
webBotAuthDownloadURL = "https://github.com/cloudflare/web-bot-auth/archive/refs/heads/main.zip"
2425
downloadTimeout = 5 * time.Minute
2526
)
@@ -311,6 +312,25 @@ func copyExtensionArtifacts(browserExtDir, outputDir string) error {
311312
return fmt.Errorf("failed to copy .crx file: %w", err)
312313
}
313314

315+
// Copy private key
316+
privateKeySrc := filepath.Join(browserExtDir, "private_key.pem")
317+
privateKeyDst := filepath.Join(outputDir, "private_key.pem")
318+
if _, err := os.Stat(privateKeySrc); err == nil {
319+
if err := util.CopyFile(privateKeySrc, privateKeyDst); err != nil {
320+
return fmt.Errorf("failed to copy private_key.pem: %w", err)
321+
}
322+
323+
// Create .gitignore to prevent private key from being uploaded
324+
gitignorePath := filepath.Join(outputDir, ".gitignore")
325+
gitignoreContent := "# Exclude private key from uploads\nprivate_key.pem\n"
326+
if err := os.WriteFile(gitignorePath, []byte(gitignoreContent), defaultFileMode); err != nil {
327+
return fmt.Errorf("failed to create .gitignore: %w", err)
328+
}
329+
pterm.Info.Println("Private key preserved (private_key.pem)")
330+
} else {
331+
pterm.Warning.Println("No private_key.pem found - extension ID may change on rebuild")
332+
}
333+
314334
return nil
315335
}
316336

@@ -332,5 +352,6 @@ func displayWebBotAuthSuccess(outputDir, extensionID, hostURL string) {
332352
pterm.Printf("2. Use in your browser, or upload to a session:\n")
333353
pterm.Printf(" kernel browsers create --extension %s\n", extensionID)
334354
pterm.Printf(" or run kernel browsers extensions upload <session-id> %s\n\n", outputDir)
335-
pterm.Warning.Println("⚠️ Keep private_key.pem secure - it determines your extension ID!")
355+
pterm.Warning.Println("⚠️ Private key saved to private_key.pem - keep it secure!")
356+
pterm.Info.Println(" It's automatically excluded when uploading via .gitignore")
336357
}

0 commit comments

Comments
 (0)