Skip to content

Commit 2ad2ed7

Browse files
thymikeeclaude
andcommitted
refactor(host): refuse a relative provider app path that names no working directory
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 3daf689 commit 2ad2ed7

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎packages/provider-webdriver/src/webdriver-utils.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@ test('the hub app resolver passes references through, uploads local files, and p
141141
}
142142
});
143143

144+
test('the hub app resolver refuses a relative app path when the request names no working directory', async () => {
145+
const uploadFile = vi.fn(async () => 'hub://never');
146+
147+
await assert.rejects(
148+
resolveHubAppReference({
149+
service: 'Hub',
150+
app: 'App.apk',
151+
referenceLabel: 'a hub:// app id',
152+
...hubReferenceGrammar,
153+
uploadFile,
154+
}),
155+
(error: unknown) => {
156+
assert.ok(error instanceof AppError);
157+
assert.equal(error.code, 'INVALID_ARGS');
158+
assert.equal(error.details?.reason, 'provider_app_cwd_missing');
159+
return true;
160+
},
161+
);
162+
assert.equal(uploadFile.mock.calls.length, 0);
163+
});
164+
144165
test('appFileUploadForm carries a regular app file and refuses anything else typed', async () => {
145166
const tempDir = await mkdtempForTest('agent-device-upload-form-');
146167
try {

‎packages/provider-webdriver/src/webdriver-utils.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export async function resolveHubAppReference(options: {
165165
const reference = options.parseReference(app);
166166
if (reference !== undefined) return reference;
167167
if (/^https?:\/\//i.test(app)) return app;
168-
const appPath = path.resolve(options.cwd ?? process.cwd(), app);
168+
const appPath = path.isAbsolute(app) ? app : path.resolve(requireAppCwd(options), app);
169169
if (!fs.existsSync(appPath)) {
170170
throw new AppError(
171171
'INVALID_ARGS',
@@ -176,6 +176,17 @@ export async function resolveHubAppReference(options: {
176176
return await options.uploadFile(appPath, options.signal);
177177
}
178178

179+
// A relative app path needs the working directory of the client that named it; the daemon fills it
180+
// from the request, and no ambient directory stands in for a request that names none.
181+
function requireAppCwd(options: { service: string; app: string; cwd?: string }): string {
182+
if (options.cwd !== undefined) return options.cwd;
183+
throw new AppError(
184+
'INVALID_ARGS',
185+
`${options.service} --provider-app ${options.app} is a relative path and the request names no working directory; pass an absolute path.`,
186+
{ providerApp: options.app, reason: 'provider_app_cwd_missing' },
187+
);
188+
}
189+
179190
const PROVIDER_API_TIMEOUT_MS = 15_000;
180191

181192
/** Service name and remediation hints a verification failure carries. */

0 commit comments

Comments
 (0)