Skip to content

A malformed --profile name silently corrupts ~/.testsprite/credentials (key not persisted) #20

Closed

Description

@Davidson3556

Summary

The profile name (--profile / TESTSPRITE_PROFILE) is written verbatim as an INI section header ([name]) in ~/.testsprite/credentials, but is never validated. A name containing characters that break the INI grammar corrupts the file or silently fails to persist the credential.

Reproduction (round-trip of the pure serialize/parse helpers)

import { serializeCredentials, parseCredentials } from '@testsprite/testsprite-cli/dist/lib/credentials.js';

const file = { 'prod]': { apiKey: 'sk-123', apiUrl: 'https://api.testsprite.com' } };
console.log(serializeCredentials(file));
// [prod]]
// api_key = sk-123
// api_url = https://api.testsprite.com
console.log(Object.keys(parseCredentials(serializeCredentials(file))));
// []   <-- the section AND its api_key/api_url lines are silently dropped

So testsprite setup --profile "prod]" would report success while the key never persists (the next command can't read it back). Other corrupting inputs:

  • a newline in the name splits the header across two lines;
  • leading/trailing whitespace doesn't round-trip (the parser trims section names, so [ prod ] reads back as prod).

Suggested fix

Validate the profile name against a conservative allowlist (letters, digits, dot, underscore, hyphen — covering default, prod, ci-staging, team.qa) at the profile-keyed credential entry points (readProfile / writeProfile / deleteProfile), throwing a typed VALIDATION_ERROR (exit 5) before any file write.

I have a PR ready for this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions