Skip to content

Commit 793df95

Browse files
authored
Merge pull request #259 from dgageot/escape-pwd
Escape passwords
2 parents 9d791c6 + fc99eba commit 793df95

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/extension/host-binary/cmd/main.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/base64"
56
"encoding/json"
67
"fmt"
78
"os"
@@ -164,8 +165,9 @@ func runUnauthorizeApp(ctx context.Context, opts unauthorizeOptions) error {
164165
}
165166

166167
type addOptions struct {
167-
Name string
168-
Value string
168+
Name string
169+
Value string
170+
Base64 bool
169171
}
170172

171173
type deleteOptions struct {
@@ -187,6 +189,7 @@ func AddSecret(ctx context.Context) *cobra.Command {
187189
_ = cmd.MarkFlagRequired("name")
188190
flags.StringVarP(&opts.Value, "value", "v", "", "Value of the secret")
189191
_ = cmd.MarkFlagRequired("value")
192+
flags.BoolVar(&opts.Base64, "base64", false, "Is the value base64 encoded")
190193
return cmd
191194
}
192195

@@ -228,7 +231,17 @@ func runAddSecret(ctx context.Context, opts addOptions) error {
228231
if err := assertMcpPolicyExists(ctx, c); err != nil {
229232
return err
230233
}
231-
return c.SetSecret(ctx, secretsapi.Secret{Name: opts.Name, Value: opts.Value, Policies: []string{mcpPolicyName}})
234+
235+
value := opts.Value
236+
if opts.Base64 {
237+
decodedValue, err := base64.StdEncoding.DecodeString(value)
238+
if err != nil {
239+
return fmt.Errorf("failed to decode base64 value: %w", err)
240+
}
241+
value = string(decodedValue)
242+
}
243+
244+
return c.SetSecret(ctx, secretsapi.Secret{Name: opts.Name, Value: value, Policies: []string{mcpPolicyName}})
232245
}
233246

234247
func runListSecrets(ctx context.Context) error {

src/extension/ui/src/Secrets.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { v1 } from "@docker/extension-api-client-types";
44
import { CatalogItemWithName } from "./types/catalog";
55
import { Secret } from "./types/secrets";
6+
import { encode } from "js-base64";
67

78
namespace Secrets {
89
export async function getSecrets(
@@ -29,11 +30,13 @@ namespace Secrets {
2930
secret: Secret
3031
): Promise<void> {
3132
try {
33+
const base64Value = encode(secret.value ?? '');
3234
const response = await client.extension.host?.cli.exec("host-binary", [
3335
"--name",
3436
secret.name,
37+
"--base64",
3538
"--value",
36-
client.host.platform === "win32" ? `\"${secret.value}\"` : `'${secret.value}'`,
39+
client.host.platform === "win32" ? `\"${base64Value}\"` : `'${base64Value}'`,
3740
]);
3841
if (!response) {
3942
client.desktopUI.toast.error(

0 commit comments

Comments
 (0)