2016-09-13 26 views
1

我一直在使用sails.js幾天,現在我開始創建我的用戶模型和REST API。我還將Passport實施到用戶身份驗證的應用程序中。我正忙着處理我的請求,並發現我可以用其他用戶數據做任何事情,即使我以不同的用戶身份登錄,但不提供密碼(只是id)。似乎任何人都可以在未經許可的情況下入侵和刪除所有用戶數據。這是故意排除在藍圖API之外的,我是否錯過了一些剛剛飛過我頭腦的重大話題?我是否需要添加更改權限的其他功能?評論我是否需要發佈任何代碼來提供幫助。爲什麼任何人在sails.js blueprint rest api中無任何用戶PUT/POST/GET而無需身份驗證?

回答

1

默認情況下,藍圖和路線並不安全,他們爲什麼要這樣做?您可以使用政策http://sailsjs.org/documentation/concepts/policies(如

{ 
    ProfileController: { 
    // Apply 'isLoggedIn' by default to all actions that are NOT specified below 
    '*': 'isLoggedIn', 
    // If an action is explicitly listed, its policy list will override the default list. 
    // So, we have to list 'isLoggedIn' again for the 'edit' action if we want it to be applied. 
    edit: ['isAdmin', 'isLoggedIn'] 
    } 
}