Skip to content

Latest commit

 

History

History
113 lines (81 loc) · 2.94 KB

File metadata and controls

113 lines (81 loc) · 2.94 KB

Security Fix: Removed Hardcoded Secret Keys

Issue

The test file lib/stellar/__tests__/payments.test.ts contained a hardcoded Stellar testnet secret key:

sourceSecretKey: "SDTIZXLNUEXETRYIBQKYQ7MO3YXRKBPPTRJDZODQHZT57LZ7DBNENRTC";

While this is a testnet key with no real value, hardcoding secrets in code is a security anti-pattern that should be avoided.

Fix Applied

1. Updated Test Configuration

Changed from hardcoded values to environment variables:

const TEST_CONFIG = {
  sourcePublicKey: process.env.TEST_STELLAR_PUBLIC_KEY || "GXXXXXXXXX...",
  sourceSecretKey: process.env.TEST_STELLAR_SECRET_KEY || "",
  destinationPublicKey:
    process.env.TEST_STELLAR_DESTINATION_KEY || "GXXXXXXXXX...",
  amount: "10.0000000",
  network: "testnet" as const,
};

2. Updated Test Logic

Modified Test 7 to skip if secret key is not provided:

if (!TEST_CONFIG.sourceSecretKey) {
  console.log(
    "   ⚠️  SKIPPED: Set TEST_STELLAR_SECRET_KEY environment variable"
  );
  console.log("   📝 Example: TEST_STELLAR_SECRET_KEY=SXXXXXXX... npx tsx ...");
} else {
  // Run submission test
}

3. Created Supporting Files

.env.test.example - Template for test environment variables

TEST_STELLAR_PUBLIC_KEY=GXXXXXXXXX...
TEST_STELLAR_SECRET_KEY=SXXXXXXXXX...
TEST_STELLAR_DESTINATION_KEY=GXXXXXXXXX...
NEXT_PUBLIC_STELLAR_NETWORK=testnet

lib/stellar/__tests__/README.md - Comprehensive testing guide with:

  • Setup instructions
  • Security best practices
  • Environment variable documentation
  • Troubleshooting guide

4. Verified .gitignore

Confirmed that .env* is already in .gitignore, which will prevent .env.test from being committed.

Usage

Developers can now run tests securely:

# Option 1: Using .env.test file
cp .env.test.example .env.test
# Edit .env.test with your keys
npx tsx lib/stellar/__tests__/payments.test.ts

# Option 2: Export environment variables
export TEST_STELLAR_SECRET_KEY="SXXXXXXX..."
npx tsx lib/stellar/__tests__/payments.test.ts

Security Benefits

✅ No secrets in version control ✅ Follows security best practices ✅ Easy to rotate keys ✅ Clear documentation for developers ✅ Tests still fully functional

Files Changed

  1. lib/stellar/__tests__/payments.test.ts - Removed hardcoded secret, added env var support
  2. .env.test.example - Created template file
  3. lib/stellar/__tests__/README.md - Created comprehensive guide
  4. Verified .gitignore includes .env*

Verification

Run the test to verify it works:

# Without secret key - Test 7 will be skipped
npx tsx lib/stellar/__tests__/payments.test.ts

# With secret key - All tests run
TEST_STELLAR_SECRET_KEY="SXXXXXXX..." npx tsx lib/stellar/__tests__/payments.test.ts

Status: ✅ Security issue resolved Impact: No functionality lost, improved security posture Breaking Changes: None (tests still work, just require env vars)