diff --git a/packages/feathers/src/application.ts b/packages/feathers/src/application.ts index 88ced8e0cd..6abf661b1e 100644 --- a/packages/feathers/src/application.ts +++ b/packages/feathers/src/application.ts @@ -62,7 +62,7 @@ export class Feathers location: L ): FeathersService { const path = (stripSlashes(location) || '/') as L - const current = this.services[path] + const current = this.services.hasOwnProperty(path) ? this.services[path] : undefined if (typeof current === 'undefined') { this.use(path, this.defaultService(path) as any) diff --git a/packages/feathers/test/application.test.ts b/packages/feathers/test/application.test.ts index 0fbe74f44a..ea5a937741 100644 --- a/packages/feathers/test/application.test.ts +++ b/packages/feathers/test/application.test.ts @@ -306,6 +306,20 @@ describe('Feathers application', () => { assert.ok((wrappedService.create as any)[TEST]) }) + + it('.service does does not access object properties', async () => { + const app = feathers() + + assert.throws(() => app.service('something'), { + message: "Can not find service 'something'" + }) + assert.throws(() => app.service('__proto__'), { + message: "Can not find service '__proto__'" + }) + assert.throws(() => app.service('toString'), { + message: "Can not find service 'toString'" + }) + }) }) describe('Express app options compatibility', function () {