@@ -36,7 +36,7 @@ export interface SharedConfigFiles {
3636
3737const swallowError = ( ) => ( { } ) ;
3838
39- export function loadSharedConfigFiles ( init : SharedConfigInit = { } ) : Promise < SharedConfigFiles > {
39+ export const loadSharedConfigFiles = ( init : SharedConfigInit = { } ) : Promise < SharedConfigFiles > = > {
4040 const {
4141 filepath = process . env [ ENV_CREDENTIALS_PATH ] || join ( getHomeDir ( ) , ".aws" , "credentials" ) ,
4242 configFilepath = process . env [ ENV_CONFIG_PATH ] || join ( getHomeDir ( ) , ".aws" , "config" ) ,
@@ -52,10 +52,10 @@ export function loadSharedConfigFiles(init: SharedConfigInit = {}): Promise<Shar
5252 credentialsFile,
5353 } ;
5454 } ) ;
55- }
55+ } ;
5656
5757const profileKeyRegex = / ^ p r o f i l e \s ( [ " ' ] ) ? ( [ ^ \1] + ) \1$ / ;
58- function normalizeConfigFile ( data : ParsedIniData ) : ParsedIniData {
58+ const normalizeConfigFile = ( data : ParsedIniData ) : ParsedIniData => {
5959 const map : ParsedIniData = { } ;
6060 for ( const key of Object . keys ( data ) ) {
6161 let matches : Array < string > | null ;
@@ -71,16 +71,20 @@ function normalizeConfigFile(data: ParsedIniData): ParsedIniData {
7171 }
7272
7373 return map ;
74- }
74+ } ;
7575
76- function parseIni ( iniData : string ) : ParsedIniData {
76+ const profileNameBlockList = [ "__proto__" , "profile __proto__" ] ;
77+ const parseIni = ( iniData : string ) : ParsedIniData => {
7778 const map : ParsedIniData = { } ;
7879 let currentSection : string | undefined ;
7980 for ( let line of iniData . split ( / \r ? \n / ) ) {
8081 line = line . split ( / ( ^ | \s ) [ ; # ] / ) [ 0 ] ; // remove comments
8182 const section = line . match ( / ^ \s * \[ ( [ ^ \[ \] ] + ) ] \s * $ / ) ;
8283 if ( section ) {
8384 currentSection = section [ 1 ] ;
85+ if ( profileNameBlockList . includes ( currentSection ) ) {
86+ throw new Error ( `Found invalid profile name "${ currentSection } "` ) ;
87+ }
8488 } else if ( currentSection ) {
8589 const item = line . match ( / ^ \s * ( .+ ?) \s * = \s * ( .+ ?) \s * $ / ) ;
8690 if ( item ) {
@@ -91,10 +95,10 @@ function parseIni(iniData: string): ParsedIniData {
9195 }
9296
9397 return map ;
94- }
98+ } ;
9599
96- function slurpFile ( path : string ) : Promise < string > {
97- return new Promise ( ( resolve , reject ) => {
100+ const slurpFile = ( path : string ) : Promise < string > =>
101+ new Promise ( ( resolve , reject ) => {
98102 readFile ( path , "utf8" , ( err , data ) => {
99103 if ( err ) {
100104 reject ( err ) ;
@@ -103,14 +107,13 @@ function slurpFile(path: string): Promise<string> {
103107 }
104108 } ) ;
105109 } ) ;
106- }
107110
108- function getHomeDir ( ) : string {
111+ const getHomeDir = ( ) : string => {
109112 const { HOME , USERPROFILE , HOMEPATH , HOMEDRIVE = `C:${ sep } ` } = process . env ;
110113
111114 if ( HOME ) return HOME ;
112115 if ( USERPROFILE ) return USERPROFILE ;
113116 if ( HOMEPATH ) return `${ HOMEDRIVE } ${ HOMEPATH } ` ;
114117
115118 return homedir ( ) ;
116- }
119+ } ;
0 commit comments