-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[ATTACK on parse-server] Is there a way to know if it's count operation request in beforeFind? #3813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@flovilmart would be really grateful if you could help. Thanks a lot! |
You should probably block the IP address of the attacker, you can disable public find (requireAuthentication: true) on the class |
Hi! Thanks a lot for a prompt reply, the problem is, he change the ip every hour or so and about the requiresAuthentication, he also create an account for that. (Yes we block the account but he'll just create a new one) Is there a way to just block the count operation? we never use it in our client so that's totally fine. if you can point me to where I can do that'd be great. Thank you so much and hope to hear from you soon |
Something you can explore is setting the query timeout to an acceptable value (within range of you regular operations) (maxTimeMS) in your parse server constuctor under databaseOptions:
The queries will timeout / close after 200ms. Then you should probably inspect the queries in a middleware (before parse-server) and reject the ones that have counts.
|
Hi! Thank you very much for your reply, I really really appreciate your help. We did try that but the req.query is empty. This is how we did it:
Any suggestion? Thank you so much! |
Just a quick question, is there a way to know it from beforeFind? when I test with the count request, the request inside beforeFind is empty |
did you setup your middleware before parse-server? Also note that it can go through he POST body if he's using the same vector as the JS-SDK is using. looking there: https://github.com/parse-community/parse-server/blob/master/src/Routers/ClassesRouter.js#L12 |
TBH I had other plans for my Saturday evening. We usually don't provide hands on support for those situations. Send away your index.js so I can have a 👀 (with redacted apiKeys/ master/DB etc..) for Florent [at] flovilmart [dot] com |
Hey man, Thank you so much!!!! appreciate your help. I've just sent it to you. Cheers! |
alright, got it! |
Closing that one for now. Also, on the beforeFind (to address the original question), the query doesn't have a count property on it as it's a transient option, I can add it alongside the request probably. |
Hey Florian, That would be really great :-) I'll close the issue since there's already pr for it |
We also suffered from this issue once but we figure out how to solve it permanently without depending on Parse itself we use parse and we love using it! this is just maybe the costs of using open source, because everybody can learn from source code to find exploits or bugs that bad people can use ... It is very common in the open source world, think about people who were using WordPress or phpBB, it is easy to attack blogs or forums using these softwares. We are hosting our servers on AWS and were using mLab for our MonogDB instances, we thought to use PostgreSQL backed by AWS RDS, but at the moment parse has poor support to it and still need much work, in addition we will miss the power that MongoDB offers (flexibility, scalability ... and cost effectiveness) The kind of attack you mentioned is targeting MongoDB, we suffered from this when we were using mLab, cause mLab seems to use default configurations. There were a lot we could do if we had control and full access to our MongoDB instances. Unfortunately mLab support cannot do a lot for you if you weren't using the dedicated plan, which is really expensive! These Docs helped us to setup our MongoDB and Parse Server correctly to ensure high scalability and availablity I will summarize what we learnt and did: Note : this is only relevant if you were using AWS. Route53We had to move our domains to use the DNS Service offered by AWS which called Route53, a reliable, fast, cost effective, scalable and high available DNS Service that works perfectly with AWS Services Load BalancingYou must use Load Balancer and deploy your Parse Server on at least 2 EC2 instances, you can also use Auto-Scalling group and let AWS scales your Parse Server up and down based on the load (request/sec, CPU ... etc). Make sure to run Parse Server behind a Reversed Proxy like HAProxy or NGINX, we are using NGINX. It is also good to consider deploying your instances on Private Network. The easiest way to do this is to use AWS Application ELB with SSL and Health Check enabled. Although I'm not really fun of AWS ELB and prefer to use NGINX also as Load Balancer. If you use AWS ELB, you also need to continue using NGINX as Reversed Proxy, because NGINX handles requests better than just using naked NodeJS. With NGINX I have full control what it can do and can optimize it based on my needs, but it is really pain in the ass if you are not familiar with it. If you don't want to have much pain, ELB is a good option to go with. In case you use NGINX then you need to create an "A" DNS record on your domain with multiple IPs and put the IPs of the EC2 instances, where your NGINX is running. This looks like this:
Setup your Load Balancer in Public Network and let it routes traffics to the instances in Private Network, where Parse Server is running. Use Load Balancer no matter how big is your App Replication/Sharding on MongoDBI talked first about MongoDB at the beginning, because it is really imported because, once your MongoDB instances are slow or partially dead, nothing else can help you to keep your app available and reachable. But why shard ?It is better to shard at early stage because sharding helps to balance loads among your instances, sometimes your queries can run a bit slower because Sharding is really useful to minimize the effects of the kind of attacks described in this issue. Although sharding will make We had to modify our Parse Server to pass Use Network Optimized/Enhanced EC2 InstancesA use IO Optimized EBSIf you use General Purpose EBS (GP2) with your MongoDB instances you will have bad performance, because you don't have enough IO Throughput. Operations like This is also one of the reasons why we stopped using mLab because mLab uses GP2 on all its plans except with the Use Placement GroupsCreate multiple EC2 instances launched in a Placement Group use the highest Network throughput, this is useful for MongoDB replication to prevent replication lag and network latency and help reduce the You can (but should and must not) also deploy Parse Server to the same Placement Group so it can reach your MongoDB but you need to considers these limitation before doing http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html#concepts-placement-groups CAUTION: if this is not well setup, it will work against you! Use AWS WAF and AWS ShieldAt the late beginning we used However you need to configure a lot of things and set rules by yourself. Cloudflare collects logs and learns from attacks from different clients then it auto create rules. This is good if you were using Wordpress or any popular CMS or Software, but if you use your own API or a non-popular software or something like (Parse Server), there are really not many advantages in using Cloudflare. Cloudflare lets you also define up to 25 Rules but only on their expensive Business and Enterprise Plans. AWS Shield gives you access to 24x7 DDoS Response Team, they are better than Cloudflare Support Team. use CloudFrontIf you have a web application, serve your css/js/images through AWS CloudFront @flovilmart If you find this reasonable add it to the docs or I can add it too with PR whenever I find time ? |
Would be nice part of the docs repo, perhaps a new section for mongodb scaling and AWS best practices. Thanks for sharing and pushing Parse-server to the limits :) |
@benedickt12 Also:
You can pass the database options right in the parse constructor with
yes but comes at a high cost if querying on non shard key etc... I would not recommend sharding unless you really know what you're doing AND you'll have operational benefits of sharding not only mitigation of that kind of attack :) |
Thank you so much for sharing, that's definitely something we're discussing within the team. We're already using Elastic Beanstalk as a loadbalancer. The other way is to verify each request and make sure that the request is fall into the option that we predefined. This definitely make it a bit harder for developer cause you can't query freely anymore but ultimately solve all other unwanted query. |
I'm not sure how feasible it is, to verify all requests. Well in AWS WAF or Cloudflare Business you can setup rules and define requests that will should be blocked/filtered by the service, you don't need to do that on the Parse Server level by adding some middlewares. But for the case you described your request for count on parse look like this
it is normal request that Parse SDK would call when you do this
Good Luck!. |
Hi there,
We got an attack by creating count request to the largest collection and we would like to prevent this. Is there a way to know if it's a count request? so that we can block it?
Thank you so much in advance!
The text was updated successfully, but these errors were encountered: