Skip to content
Merged
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
1 change: 1 addition & 0 deletions components/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ async function deployComponent(req) {
allowInstallScripts: req.install_allow_scripts,
};
}
if (req.urlPath !== undefined) applicationConfig.urlPath = req.urlPath;
await configUtils.addConfig(req.project, applicationConfig);
}

Expand Down
10 changes: 9 additions & 1 deletion components/operationsValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,15 @@ function deployComponentValidator(req) {
install_timeout: Joi.number().optional(),
install_allow_scripts: Joi.boolean().optional(),
force: Joi.boolean().optional(),
});
urlPath: Joi.string()
.min(1)
.custom((value, helpers) => {
if (value.includes('..')) return helpers.error('any.invalid');
return value;
})
.optional()
.messages({ 'any.invalid': 'urlPath must not contain ".."' }),
}).with('urlPath', 'package');

return validator.validateBySchema(req, deployProjSchema);
}
39 changes: 39 additions & 0 deletions unitTests/server/fastifyRoutes/operationsValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,43 @@ describe('Test operationsValidation module', () => {
expect(result.message).to.equal('Project name can only contain alphanumeric, dash and underscores characters');
});
});

describe('Test deployComponentValidator function', () => {
it('accepts valid package-based deploy request', () => {
const result = validator.deployComponentValidator({ project: 'my-app', package: '@scope/pkg' });
expect(result).to.be.undefined;
});

it('accepts urlPath alongside package', () => {
const result = validator.deployComponentValidator({ project: 'my-app', package: '@scope/pkg', urlPath: '/api' });
expect(result).to.be.undefined;
});

it('rejects urlPath without package', () => {
const result = validator.deployComponentValidator({ project: 'my-app', urlPath: '/api' });
expect(result).to.be.ok;
expect(result.message).to.include('urlPath');
});

it('rejects urlPath containing ..', () => {
const result = validator.deployComponentValidator({
project: 'my-app',
package: 'pkg',
urlPath: '../etc/passwd',
});
expect(result).to.be.ok;
expect(result.message).to.include('urlPath');
});

it('rejects empty urlPath', () => {
const result = validator.deployComponentValidator({ project: 'my-app', package: 'pkg', urlPath: '' });
expect(result).to.be.ok;
});

it('rejects missing project', () => {
const result = validator.deployComponentValidator({ package: 'pkg' });
expect(result).to.be.ok;
expect(result.message).to.include('project');
});
});
});
Loading