Skip to content

Commit d567bb3

Browse files
baslu93Luca Bassani
authored andcommitted
fix: avoid possible sql injection in userrole query
1 parent 6782fc7 commit d567bb3

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

messages/create.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ This command works with only scratch orgs.
8282

8383
This command doesn't work when authorizing an org using the JWT flow if the org is on Hyperforce.
8484

85+
# error.invalidRoleDeveloperName
86+
87+
Invalid roleDeveloperName: "%s". Must start with a letter and contain only alphanumeric characters or single underscores, with no double or final underscores.
88+
8589
# error.jwtHyperforce.actions
8690

8791
- Authorize your Dev Hub with either the `org login web` or `org login sfdx-url` command. You can then successfully use the `org create user` command on scratch orgs that you create with your Dev Hub.

src/commands/org/create/user.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ export class CreateUserCommand extends SfCommand<CreateUserOutput> {
227227
if (defaultFields['roleDeveloperName']) {
228228
// @ts-expect-error roleDeveloperName is not a valid field on UserFields
229229
const devName = defaultFields['roleDeveloperName'] as string;
230+
if (!/^[a-z](?!.*__)(?!.*_$)\w*$/i.test(devName)) {
231+
throw messages.createError('error.invalidRoleDeveloperName', [devName]);
232+
}
230233
logger.debug(`Querying org for user role name [${devName}]`);
231234
const userRole = await this.flags['target-org']
232235
.getConnection(this.flags['api-version'])

test/commands/create.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,5 +431,19 @@ describe('org:create:user', () => {
431431
);
432432
}
433433
});
434+
435+
it('will handle a failed `createUser` call with a InvalidRoleDeveloperName error', async () => {
436+
await prepareStubs({}, true);
437+
try {
438+
await CreateUserCommand.run(['--json', '--target-org', testOrg.username,'roleDeveloperName=_Invalid_Role']);
439+
expect.fail('should have thrown an error');
440+
} catch (e) {
441+
assert(e instanceof Error);
442+
expect(e.name).to.equal('InvalidRoleDeveloperNameError');
443+
expect(e.message).to.equal(
444+
'Invalid roleDeveloperName: "_Invalid_Role". Must start with a letter and contain only alphanumeric characters or single underscores, with no double or final underscores.'
445+
);
446+
}
447+
});
434448
});
435449
});

0 commit comments

Comments
 (0)