@@ -36,7 +36,7 @@ export interface SharedConfigFiles {
36
36
37
37
const swallowError = ( ) => ( { } ) ;
38
38
39
- export function loadSharedConfigFiles ( init : SharedConfigInit = { } ) : Promise < SharedConfigFiles > {
39
+ export const loadSharedConfigFiles = ( init : SharedConfigInit = { } ) : Promise < SharedConfigFiles > = > {
40
40
const {
41
41
filepath = process . env [ ENV_CREDENTIALS_PATH ] || join ( getHomeDir ( ) , ".aws" , "credentials" ) ,
42
42
configFilepath = process . env [ ENV_CONFIG_PATH ] || join ( getHomeDir ( ) , ".aws" , "config" ) ,
@@ -52,10 +52,10 @@ export function loadSharedConfigFiles(init: SharedConfigInit = {}): Promise<Shar
52
52
credentialsFile,
53
53
} ;
54
54
} ) ;
55
- }
55
+ } ;
56
56
57
57
const profileKeyRegex = / ^ p r o f i l e \s ( [ " ' ] ) ? ( [ ^ \1] + ) \1$ / ;
58
- function normalizeConfigFile ( data : ParsedIniData ) : ParsedIniData {
58
+ const normalizeConfigFile = ( data : ParsedIniData ) : ParsedIniData => {
59
59
const map : ParsedIniData = { } ;
60
60
for ( const key of Object . keys ( data ) ) {
61
61
let matches : Array < string > | null ;
@@ -71,16 +71,20 @@ function normalizeConfigFile(data: ParsedIniData): ParsedIniData {
71
71
}
72
72
73
73
return map ;
74
- }
74
+ } ;
75
75
76
- function parseIni ( iniData : string ) : ParsedIniData {
76
+ const profileNameBlockList = [ "__proto__" , "profile __proto__" ] ;
77
+ const parseIni = ( iniData : string ) : ParsedIniData => {
77
78
const map : ParsedIniData = { } ;
78
79
let currentSection : string | undefined ;
79
80
for ( let line of iniData . split ( / \r ? \n / ) ) {
80
81
line = line . split ( / ( ^ | \s ) [ ; # ] / ) [ 0 ] ; // remove comments
81
82
const section = line . match ( / ^ \s * \[ ( [ ^ \[ \] ] + ) ] \s * $ / ) ;
82
83
if ( section ) {
83
84
currentSection = section [ 1 ] ;
85
+ if ( profileNameBlockList . includes ( currentSection ) ) {
86
+ throw new Error ( `Found invalid profile name "${ currentSection } "` ) ;
87
+ }
84
88
} else if ( currentSection ) {
85
89
const item = line . match ( / ^ \s * ( .+ ?) \s * = \s * ( .+ ?) \s * $ / ) ;
86
90
if ( item ) {
@@ -91,10 +95,10 @@ function parseIni(iniData: string): ParsedIniData {
91
95
}
92
96
93
97
return map ;
94
- }
98
+ } ;
95
99
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 ) => {
98
102
readFile ( path , "utf8" , ( err , data ) => {
99
103
if ( err ) {
100
104
reject ( err ) ;
@@ -103,14 +107,13 @@ function slurpFile(path: string): Promise<string> {
103
107
}
104
108
} ) ;
105
109
} ) ;
106
- }
107
110
108
- function getHomeDir ( ) : string {
111
+ const getHomeDir = ( ) : string => {
109
112
const { HOME , USERPROFILE , HOMEPATH , HOMEDRIVE = `C:${ sep } ` } = process . env ;
110
113
111
114
if ( HOME ) return HOME ;
112
115
if ( USERPROFILE ) return USERPROFILE ;
113
116
if ( HOMEPATH ) return `${ HOMEDRIVE } ${ HOMEPATH } ` ;
114
117
115
118
return homedir ( ) ;
116
- }
119
+ } ;
0 commit comments