Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3361,10 +3361,15 @@ async function runCli(): Promise<void> {
yargs,
'env',
'Show WORKOS_* environment variables and their effects',
(y) => y,
async () => {
(y) =>
y.option('show-secrets', {
type: 'boolean',
default: false,
describe: 'Show unredacted API keys',
}),
async (argv) => {
const { runDebugEnv } = await import('./commands/debug.js');
await runDebugEnv();
await runDebugEnv({ showSecrets: argv.showSecrets as boolean });
},
);
registerSubcommand(
Expand Down
34 changes: 30 additions & 4 deletions src/commands/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ describe('debug commands', () => {
it('shows set env vars with values', async () => {
process.env.WORKOS_FORCE_TTY = '1';

await runDebugEnv();
await runDebugEnv({ showSecrets: false });

const output = consoleOutput.join('\n');
expect(output).toContain('WORKOS_FORCE_TTY');
Expand All @@ -584,7 +584,7 @@ describe('debug commands', () => {
it('shows unset env vars with descriptions', async () => {
delete process.env.WORKOS_API_KEY;

await runDebugEnv();
await runDebugEnv({ showSecrets: false });

const output = consoleOutput.join('\n');
expect(output).toContain('WORKOS_API_KEY');
Expand All @@ -595,7 +595,7 @@ describe('debug commands', () => {
jsonMode = true;
process.env.WORKOS_DEBUG = '1';

await runDebugEnv();
await runDebugEnv({ showSecrets: false });

const parsed = JSON.parse(consoleOutput[0]);
expect(parsed.variables.WORKOS_DEBUG.value).toBe('1');
Expand All @@ -605,10 +605,36 @@ describe('debug commands', () => {
delete process.env.WORKOS_DEBUG;
});

it('masks WORKOS_API_KEY in human and JSON output', async () => {
process.env.WORKOS_API_KEY = 'sk_test_abcdefghijklmnop';

await runDebugEnv({ showSecrets: false });
jsonMode = true;
await runDebugEnv({ showSecrets: false });

const output = consoleOutput.join('\n');
expect(output).not.toContain('sk_test_abcdefghijklmnop');
expect(output).toContain('sk_t****mnop');
expect(JSON.parse(consoleOutput[consoleOutput.length - 1]).variables.WORKOS_API_KEY.value).toBe('sk_t****mnop');

delete process.env.WORKOS_API_KEY;
});

it('shows WORKOS_API_KEY unmasked with --show-secrets', async () => {
jsonMode = true;
process.env.WORKOS_API_KEY = 'sk_test_abcdefghijklmnop';

await runDebugEnv({ showSecrets: true });

expect(JSON.parse(consoleOutput[0]).variables.WORKOS_API_KEY.value).toBe('sk_test_abcdefghijklmnop');

delete process.env.WORKOS_API_KEY;
});

it('lists all known env vars', async () => {
jsonMode = true;

await runDebugEnv();
await runDebugEnv({ showSecrets: false });

const parsed = JSON.parse(consoleOutput[0]);
expect(Object.keys(parsed.variables)).toContain('WORKOS_API_KEY');
Expand Down
10 changes: 5 additions & 5 deletions src/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ interface EnvVarInfo {
* (env-var-catalog.spec.ts) scans the source for `process.env.WORKOS_*` reads
* and fails if any are missing here, so this list can't silently drift.
*/
export const ENV_VAR_CATALOG: { name: string; effect: string }[] = [
export const ENV_VAR_CATALOG: { name: string; effect: string; secret?: boolean }[] = [
// Credentials
{ name: 'WORKOS_API_KEY', effect: 'Bypasses credential resolution — used directly for API calls' },
{ name: 'WORKOS_API_KEY', effect: 'Bypasses credential resolution — used directly for API calls', secret: true },
{ name: 'WORKOS_CLIENT_ID', effect: 'WorkOS client ID used during credential resolution' },
// Interaction & output
{ name: 'WORKOS_MODE', effect: 'Controls interaction behavior: human, agent, or CI' },
Expand Down Expand Up @@ -413,10 +413,10 @@ export const ENV_VAR_CATALOG: { name: string; effect: string }[] = [
},
];

export async function runDebugEnv(): Promise<void> {
const vars: EnvVarInfo[] = ENV_VAR_CATALOG.map(({ name, effect }) => ({
export async function runDebugEnv({ showSecrets }: { showSecrets: boolean }): Promise<void> {
const vars: EnvVarInfo[] = ENV_VAR_CATALOG.map(({ name, effect, secret }) => ({
name,
value: process.env[name],
value: secret && !showSecrets ? maskSecret(process.env[name]) : process.env[name],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Empty keys appear unset. With WORKOS_API_KEY='', maskSecret() returns undefined. The default output then lists the variable as unset and returns null in JSON, while --show-secrets correctly reports it as set with an empty value. Preserve the original value's presence when building the set and unset lists, and add an empty-value test.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/debug.ts
Line: 419

Comment:
**Empty keys appear unset.** With `WORKOS_API_KEY=''`, `maskSecret()` returns `undefined`. The default output then lists the variable as unset and returns `null` in JSON, while `--show-secrets` correctly reports it as set with an empty value. Preserve the original value's presence when building the `set` and `unset` lists, and add an empty-value test.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

effect,
}));

Expand Down
Loading