8***@qq.com
8***@qq.com
  • 发布:2022-03-12 23:26
  • 更新:2022-04-06 16:58
  • 阅读:383

【报Bug】schema.json 权限 存在数据泄露问题

分类:uniCloud

产品分类: uniCloud/App

示例代码:

opendb-msg.schema.json

{  
    "bsonType": "object",  
    "required": ["to_uid", "body", "type"],  
    "permission": {  
        "read": "doc.to_uid == auth.uid || doc.from_uid == auth.uid",  
        "create": "auth.uid != null",  
        "update": false,  
        "delete": false  
    },  
    "properties": {  
        "_id": {  
            "description": "ID,系统自动生成"  
        },  
        "from_uid": {  
            "bsonType": "string",  
            "description": "消息发送方 UserID(用于指定发送消息方帐号)",  
            "forceDefaultValue": {  
                "$env": "uid"  
            }  
        },  
        "to_uid": {  
            "description": "消息接收方 UserID",  
            "bsonType": "string"  
        },  
        "is_read": {  
            "description": "是否已读",  
            "bsonType": "bool",  
            "forceDefaultValue": false  
        },  
        "create_date": {  
            "bsonType": "timestamp",  
            "description": "消息发送时间戳",  
            "forceDefaultValue": {  
                "$env": "now"  
            }  
        },  
        "body": {  
            "bsonType": "object",  
            "description": "消息内容,包含的键会随type变化。需要自己写valedateFunction验证"  
        },  
        "type": {  
            "bsonType": "string",  
            "enum": [{  
                "text": "文本",  
                "value": "text"  
            }, {  
                "text": "图像",  
                "value": "image"  
            }, {  
                "text": "语音",  
                "value": "sound"  
            }, {  
                "text": "视频",  
                "value": "video"  
            }, {  
                "text": "文件",  
                "value": "file"  
            }, {  
                "text": "位置",  
                "value": "location"  
            }]  
        }  
    }  
}  

调用例子:

<template>  
    <unicloud-db v-slot:default="{data, loading, error, options}" collection="opendb-msg"  
        >  
                <!-- 按理应该提示没有权限或者只返回相关数据 -->  
        <!-- where="to_uid == $cloudEnv_uid || from_uid == $cloudEnv_uid" -->  
        {{data.length}}  
        <view class="contacts" v-for="(item,index) in data" :key="index">  
            {{item.from_uid}}对{{item.to_uid}}: {{item.body}}  
        </view>  
    </unicloud-db>  
</template>  

<script>  
    export default {  
        data() {  
            return {  

            };  
        }  
    }  
</script>  

<style lang="scss">  
    .contacts {  
        margin-top: 20rpx;  
    }  
</style>  

操作步骤:

模拟的数据:
{
"from_uid": "622a330558bba900015181d5",
"to_uid": "123",
"is_read": false,
"create_date": 0,
"body": "hello",
"type": "text"
}

{
"from_uid": "123",
"to_uid": "622a330558bba900015181d5",
"is_read": false,
"create_date": 0,
"body": "world",
"type": "text"
}

{
"from_uid": "123",
"to_uid": "123",
"is_read": false,
"create_date": 0,
"body": "预置消息",
"type": "text"
}

预期结果:

预期显示或者提示无权限
622a330558bba900015181d5对123: hello
123对622a330558bba900015181d5: world

实际结果:

622a330558bba900015181d5对123: hello
123对622a330558bba900015181d5: world
123对123: 预置消息

bug描述:

环境描述: 在使用阿里云的unicloud 中使用"uni-starter"模板进行的二次开发
uni-id-users 用户信息如图:

由于需要用到聊天系统,所以使用了 云数据库模板"opendb-msg 聊天消息"的模板
如图:

往数据库中存了2条关于登录者的数据和一条与登录者无关的消息如下图:

然后通过"permission": {
"read": "doc.to_uid == auth.uid || doc.from_uid == auth.uid",
来控制权限,期望登录者只能读取自己发送或者接收的消息,但是得到了3条数据(有一条与自己无关的)

2022-03-12 23:26 负责人:DCloud_uniCloud_WYQ 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

这个账号是个管理员账号吗?

该问题目前已经被锁定, 无法添加新回复