@@ -93,6 +93,15 @@ export interface ServiceClientConstructor {
93
93
service : ServiceDefinition ;
94
94
}
95
95
96
+ /**
97
+ * Returns true, if given key is included in the blacklisted
98
+ * keys.
99
+ * @param key key for check, string.
100
+ */
101
+ function isPrototypePolluted ( key : string ) : Boolean {
102
+ return [ '__proto__' , 'prototype' , 'constructor' ] . includes ( key ) ;
103
+ }
104
+
96
105
/**
97
106
* Creates a constructor for a client with the given methods, as specified in
98
107
* the methods argument. The resulting class will have an instance method for
@@ -122,7 +131,7 @@ export function makeClientConstructor(
122
131
}
123
132
124
133
Object . keys ( methods ) . forEach ( ( name ) => {
125
- if ( name === '__proto__' ) {
134
+ if ( isPrototypePolluted ( name ) ) {
126
135
return ;
127
136
}
128
137
const attrs = methods [ name ] ;
@@ -155,7 +164,7 @@ export function makeClientConstructor(
155
164
ServiceClientImpl . prototype [ name ] = methodFunc ;
156
165
// Associate all provided attributes with the method
157
166
Object . assign ( ServiceClientImpl . prototype [ name ] , attrs ) ;
158
- if ( attrs . originalName && attrs . originalName !== '__proto__' ) {
167
+ if ( attrs . originalName && ! isPrototypePolluted ( attrs . originalName ) ) {
159
168
ServiceClientImpl . prototype [ attrs . originalName ] =
160
169
ServiceClientImpl . prototype [ name ] ;
161
170
}
@@ -204,7 +213,7 @@ export function loadPackageDefinition(
204
213
if ( Object . prototype . hasOwnProperty . call ( packageDef , serviceFqn ) ) {
205
214
const service = packageDef [ serviceFqn ] ;
206
215
const nameComponents = serviceFqn . split ( '.' ) ;
207
- if ( nameComponents . some ( comp => comp === '__proto__' ) ) {
216
+ if ( nameComponents . some ( ( comp : string ) => isPrototypePolluted ( comp ) ) ) {
208
217
continue ;
209
218
}
210
219
const serviceName = nameComponents [ nameComponents . length - 1 ] ;
0 commit comments