File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const USER_AGENT = 'configure-aws-credentials-for-github-actions';
10
10
const MAX_TAG_VALUE_LENGTH = 256 ;
11
11
const SANITIZATION_CHARACTER = '_' ;
12
12
const ROLE_SESSION_NAME = 'GitHubActions' ;
13
+ const REGION_REGEX = / ^ [ a - z 0 - 9 - ] + $ / g;
13
14
14
15
async function assumeRole ( params ) {
15
16
// Assume a role to get short-lived credentials using longer-lived credentials.
@@ -151,6 +152,10 @@ async function run() {
151
152
const roleDurationSeconds = core . getInput ( 'role-duration-seconds' , { required : false } ) || MAX_ACTION_RUNTIME ;
152
153
const roleSessionName = core . getInput ( 'role-session-name' , { required : false } ) || ROLE_SESSION_NAME ;
153
154
155
+ if ( ! region . match ( REGION_REGEX ) ) {
156
+ throw new Error ( `Region is not valid: ${ region } ` ) ;
157
+ }
158
+
154
159
exportRegion ( region ) ;
155
160
156
161
// Always export the source credentials and account ID.
Original file line number Diff line number Diff line change @@ -154,6 +154,19 @@ describe('Configure AWS Credentials', () => {
154
154
expect ( core . setSecret ) . toHaveBeenCalledWith ( FAKE_ACCOUNT_ID ) ;
155
155
} ) ;
156
156
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
+
157
170
test ( 'can opt out of masking account ID' , async ( ) => {
158
171
const mockInputs = { ...CREDS_INPUTS , 'aws-region' : 'us-east-1' , 'mask-aws-account-id' : 'false' } ;
159
172
core . getInput = jest
You can’t perform that action at this time.
0 commit comments