Skip to content

Commit 3d568d2

Browse files
authored
fix: validate region input string (#44)
1 parent 75aa8f1 commit 3d568d2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const USER_AGENT = 'configure-aws-credentials-for-github-actions';
1010
const MAX_TAG_VALUE_LENGTH = 256;
1111
const SANITIZATION_CHARACTER = '_';
1212
const ROLE_SESSION_NAME = 'GitHubActions';
13+
const REGION_REGEX = /^[a-z0-9-]+$/g;
1314

1415
async function assumeRole(params) {
1516
// Assume a role to get short-lived credentials using longer-lived credentials.
@@ -151,6 +152,10 @@ async function run() {
151152
const roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || MAX_ACTION_RUNTIME;
152153
const roleSessionName = core.getInput('role-session-name', { required: false }) || ROLE_SESSION_NAME;
153154

155+
if (!region.match(REGION_REGEX)) {
156+
throw new Error(`Region is not valid: ${region}`);
157+
}
158+
154159
exportRegion(region);
155160

156161
// Always export the source credentials and account ID.

index.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ describe('Configure AWS Credentials', () => {
154154
expect(core.setSecret).toHaveBeenCalledWith(FAKE_ACCOUNT_ID);
155155
});
156156

157+
test('validates region name', async () => {
158+
process.env.SHOW_STACK_TRACE = 'false';
159+
160+
const mockInputs = {...CREDS_INPUTS, 'aws-region': '$AWS_REGION'};
161+
core.getInput = jest
162+
.fn()
163+
.mockImplementation(mockGetInput(mockInputs));
164+
165+
await run();
166+
167+
expect(core.setFailed).toHaveBeenCalledWith('Region is not valid: $AWS_REGION');
168+
});
169+
157170
test('can opt out of masking account ID', async () => {
158171
const mockInputs = {...CREDS_INPUTS, 'aws-region': 'us-east-1', 'mask-aws-account-id': 'false'};
159172
core.getInput = jest

0 commit comments

Comments
 (0)