每个用户安全性一个数据库 [英] One database per user security

查看:128
本文介绍了每个用户安全性一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Ionic开发了一个应用程序,其中每个用户都有自己的PouchDB数据库与自己的远程CouchDB数据库同步。我使用 couch_peruser = true ,因此任何想要访问其数据库的用户都需要进行身份验证。
如果我们存储用户名&本地密码或我们是否要求用户在需要同步时随时提供密码,但是这些选项都不是很好的选择(出于安全考虑或对用户不友好)。

I develop an app with Ionic where each user got its own PouchDB database synchronise with its own remote CouchDB database. I use couch_peruser=true so any user that want to access its database need to authenticate. This system is easy to do if we store the username & password locally or if we ask the user to give them anytime a sync is needed but none of these options are good (security concern or non user-friendly).

我来了带有这两个选项,但没有一个起作用。

I came with those two options, but none is working:

1)出现在我身上的最佳选择是使用 Cookie身份验证,只需将令牌保存在本地并使用它,但是很遗憾,它与令牌ouchdb连接并要求使用标题:

1) The best option that came to me was to use Cookie Authentication, just save the token locally and use it, but unfortunately to connect with the token couchdb ask to use the header :

Cookie: AuthSession={TOKEN}

但这是不可能的,因为它是未经授权的标头(不安全),并且被浏览器拒绝。

But this is not possible because it is a non-authorized header (unsafe) and is rejected by the browser.

2)第二种选择是使用couchdb代理身份验证,但这与保存用户名和密码相同,因为令牌永远有效。

2) Second option is to use couchdb Proxy Authentication but it is the same as saving the username and password as the token is valid forever.

是否有其他方法处理身份验证?我当时正在考虑使用其他用户数据库,生成伪造的密码,用户名,然后发送此凭据以保存到用户应用程序中。在这种情况下,如果安全性受到损害,则用户可以更改其密码,以便服务器也可以更改第二个密码(以我们撤消令牌的相同方式),但是仍然存在问题,因为使用被窃取的凭证始终是可能的

Is there any way other way of handling authentication ? I was thinking to use an alternative users database, generate a fake password & username then send this credential to be saved into the user app. In this case if the security is compromise the user can change its password so the server can change the second password too (in the same way we revoke a token), but then there is still a problem because with the stolen credential it is always possible to access directly to the couchdb database without being seen..

推荐答案

感谢您的帮助,我无法使用 couchdb-auth-proxy ,所以我最终得到了以下解决方案,该解决方案具有以下优势:防止直接访问ouchdb:

Thanks for your help, i was not able to use couchdb-auth-proxy so I ended up with the following solution that has the advantage to prevent direct access to couchdb :

1)创建一个节点服务器以验证用户身份,如果身份验证成功,则将ouchdb令牌返回给应用程序以进行cookie身份验证

1) Create a node server to authenticate the user, if auth successful then return couchdb token to the app for cookie authentication

2)使用 node-http-proxy

具有以下代码:

(要求此路由器代码在快速中间件中非常早出现,否则可能会更改响应并且pouchdb sync无法正常工作,因此请将其放在app.use(bodyParser.json())之前

    router.all('/*', (req: Request, res: Response, next: NextFunction) {

            let token = req.get('X-Auth-Cdb-Token');

            let httpProxy = require('http-proxy');

            const proxy = httpProxy.createProxyServer({
                target: target,
            });

            req.headers['Cookie'] = 'AuthSession='+token

            proxy.web(req, res);

    });

3)在您的应用程序中,使用以下标头设置pouchdb远程数据库:

3) In your app set the pouchdb remote database with the following header :

    remoteDB = new PouchDB(url, {
         skip_setup: true,
         ajax: {
            headers: {
                'X-Auth-Cdb-Token': couchdbToken
            },
            withCredentials: false
         }
    })

这篇关于每个用户安全性一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆