Skip to content

[Hackathon] Reject symlinked ancestors when creating the default GitHub workflow #527

Closed

Description

@ayush-that

Verified against (commit SHA or released version)

Published @testsprite/[email protected] and source commit 988c0355bb05631e9c6c1785e443937ff2a88c0e. macOS 27.2 (arm64), Node.js v26.12.0.

Discord Username / User ID

shydev69

What does this improvement do?

ci init github follows a symlinked .github directory and creates its default workflow outside the repository, without --force. The default repository workflow path should reject symlinked ancestors before creating directories or writing the file.

Details / implementation notes

Steps to reproduce

The script runs the real CLI twice: once in an ordinary fixture directory and once with .github pointing to a sibling directory. Both directories are inside one temporary root. It passes a dummy project, disables telemetry/update checks, and does not request --set-secret or --force.

From a checkout of the verified commit:

npm ci
npm run build

Save the script below as workflow-symlink.mjs, then run:

node workflow-symlink.mjs ./dist/index.js
workflow-symlink.mjs
import { mkdtempSync, mkdirSync, symlinkSync, existsSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { spawnSync } from 'node:child_process';

const cli = resolve(process.argv[2] ?? './dist/index.js');
const root = mkdtempSync(join(tmpdir(), 'testsprite-workflow-repro-'));
for (const variant of ['control', 'symlink']) {
  const repo = join(root, variant);
  const outside = join(root, `${variant}-outside`);
  mkdirSync(repo);
  mkdirSync(outside);
  if (variant === 'symlink') symlinkSync(`../${variant}-outside`, join(repo, '.github'));
  const result = spawnSync(process.execPath, [cli, 'ci', 'init', 'github',
    '--project', 'prj_fixture', '--output', 'json'], {
    cwd: repo, encoding: 'utf8', timeout: 10000,
    env: { PATH: process.env.PATH, TESTSPRITE_API_KEY: 'sk-user-dummy-repro',
      TESTSPRITE_NO_TELEMETRY: '1', TESTSPRITE_NO_UPDATE_NOTIFIER: '1', DO_NOT_TRACK: '1' },
  });
  console.log(JSON.stringify({ variant, exitCode: result.status,
    insideCreated: existsSync(join(repo, '.github/workflows/testsprite.yml')),
    outsideCreated: existsSync(join(outside, 'workflows/testsprite.yml')),
    output: result.stdout.trim(), stderr: result.stderr.trim(), error: result.error?.message,
  }));
}
console.log(`Fixture retained at ${root}`);

Actual result

Fixture CLI exit Workflow created in sibling *-outside directory
Ordinary directory 0 No
.github symlink 0 Yes

Both CLI responses report "wrote": true and "status": "written". In the symlink case, the physical destination is outside the fixture repository. Expected: reject that default path without writing into the sibling directory.

This report does not claim irreversible file destruction. The existing forced-overwrite path keeps a .bak backup.

Proposed fix

Check existing path components for symlinks before creating the default workflow, using the existing installer guard as a starting point. Preserve intentional custom --path behavior and existing backup semantics.

Relevant code: directory creation and exclusive final write, backup handling, and the existing installer guard.

Confirmations

  • I have searched existing issues and this is not a duplicate.
  • I have provided my Discord identity above for reward coordination.

Activity

  1. added
    needs-triage
    hackathon
    on Oct 18, 2026
  2. fyZhang66 commented on Oct 20, 2026

    @fyZhang66
    Contributor

    Confirmed on v0.15.0, thanks @ayush-that. ci init runs mkdir -p and writes through a symlinked .github ancestor without looking; agent install already has a symlink guard that ci init doesn't use. Accepted, scope:

    • Before creating directories or writing, refuse when any ancestor of the target path (or the file itself) is a symlink that resolves outside the repository; exit 5 and name the resolved path. Reuse the agent install guard.
    • Tests (must fail before the fix): a symlinked .github and a symlinked workflows pointing outside the repo are refused and nothing is created; a symlink that stays inside the repo still works.

    No new dependency. Comment /assign to claim it.

  3. added
    accepted
    and removed
    needs-triage
    on Oct 20, 2026
  4. ayush-that commented on Oct 21, 2026

    @ayush-that
    ContributorAuthor

    /assign

  5. added
    in-progress
    on Oct 21, 2026
  6. testsprite-hob commented on Oct 21, 2026

    @testsprite-hob

    Assigned to @ayush-that. Thanks for taking this on. (2 more slots available.)

    Your open assigned issues (1/3):
    (none)

  7. added a commit that references this issue on Nov 10, 2026
    f95ee5e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

acceptedhackathonin-progress

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions