Javascript 在未做任何更改后,Firestore在Next.js应用程序中读取的数据突然激增-请参见图表
在第1-10天的图表中,我正在做这个项目——每天可以看到100-300次的阅读,定期刷新firestore中的文档列表。第11-15天,我拜访家人,远离项目。在第16天,我启动了15分钟的项目,但没有做任何更改(我没有注意到它的峰值如此之高,因为它没有超过配额,我也没有开发或跟踪)。今天,当我在做这个项目的时候,我达到了我的自由配额。在我开始工作的两个小时内发生了突发事件 我认为这些内容来自我的Next.js应用程序中的clientList组件:Javascript 在未做任何更改后,Firestore在Next.js应用程序中读取的数据突然激增-请参见图表,javascript,firebase,google-cloud-firestore,next.js,firebase-security,Javascript,Firebase,Google Cloud Firestore,Next.js,Firebase Security,在第1-10天的图表中,我正在做这个项目——每天可以看到100-300次的阅读,定期刷新firestore中的文档列表。第11-15天,我拜访家人,远离项目。在第16天,我启动了15分钟的项目,但没有做任何更改(我没有注意到它的峰值如此之高,因为它没有超过配额,我也没有开发或跟踪)。今天,当我在做这个项目的时候,我达到了我的自由配额。在我开始工作的两个小时内发生了突发事件 我认为这些内容来自我的Next.js应用程序中的clientList组件: let unsubscribe; const C
let unsubscribe;
const Clients = () => {
const classes = useStyles();
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
const db = firebase.firestore();
unsubscribe = db.collection("users")
.doc(user.uid)
.collection("clients")
.onSnapshot((snap) => {
const clients = snap.docs.map((doc) => ({
id: doc.id,
...doc.data(),
}));
unsubscribe();
setClients(clients);
});
} else {
[];
}
});
const [clients, setClients] = useState([]);
return (
<Fragment>
{clients.map((client, i) => (
<Paper className={classes.paper} key={client.id}>
<Typography
className={client.name}
color="textSecondary"
gutterBottom
>
{client.name}
</Typography>
</Paper>
))}
</Fragment>
);
};
export default Clients;
回到这里:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// This rule allows anyone with your database reference to view, edit,
// and delete all data in your Firestore database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your Firestore database will be denied.
//
// Make sure to write security rules for your app before that time, or else
// all client requests to your Firestore database will be denied until you Update
// your rules
match /{document=**} {
allow read, write: if request.time < timestamp.date(2019, 9, 10);
}
}
}
rules_version='2';
服务云.firestore{
匹配/databases/{database}/documents{
//此规则允许任何拥有您的数据库引用的人查看、编辑、,
//并删除Firestore数据库中的所有数据。这对于获取
//已启动,但已配置为在30天后过期,因为
//使您的应用对攻击者开放。此时,所有客户端
//对Firestore数据库的请求将被拒绝。
//
//确保在此之前为你的应用编写安全规则,否则
//在更新之前,对Firestore数据库的所有客户端请求都将被拒绝
//你的规则
匹配/{document=**}{
允许读、写:如果request.time
直到我确定我原来的安全规则没问题。我最后一次提交clientList.js是在第10天。今天在项目中,我正在使用一个按钮显示和隐藏表单,这两个按钮与clientList.js(由于动态导入而称为Client)或Firestore无关
我目前不使用firebase CLI,我会打开一个firestore dashboard chrome窗口和一个localhost窗口(与未超过或接近配额的十天相同)。没有无法识别的身份验证用户,匿名身份验证不是选项
有人能告诉我如何解决类似问题吗?您可以在GCP云控制台中检查stackdriver,查看可能导致此stackdriver筛选器的高读取使用率的任何管理作业 resource.type=“数据存储\数据库” 最常见的意外使用来源包括:
- 使用托管导入和导出
- 读取文档更改事件期间活动侦听器(监视)产生的操作
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// This rule allows anyone with your database reference to view, edit,
// and delete all data in your Firestore database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your Firestore database will be denied.
//
// Make sure to write security rules for your app before that time, or else
// all client requests to your Firestore database will be denied until you Update
// your rules
match /{document=**} {
allow read, write: if request.time < timestamp.date(2019, 9, 10);
}
}
}