Skip to content
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

fix(state/statebag): filter frequent & large data from client #2362

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

AvarianKnight
Copy link
Contributor

@AvarianKnight AvarianKnight commented Jan 24, 2024

  • if we accept these willy-nilly, clients could possibly OOM the server, or do a one-to-many make-shift DoS on larger a server
  • the size limits here are kept high to keep compatibility with people who "misuse" state bags
  • sane defaults for servers that don't send large data via state bags would be set rateLimiter_stateBagSize_rate 1000 and set rateLimiter_stateBagSize_burst 4000

Goal of this PR

Fix the possible abuse cases for state bags, though this doesn't cover all of them theres already another pr sitting that allows better filtering.

How is this PR achieving the goal

The rate and size of state bags similar to msgServerEvent

This PR applies to the following area(s)

Server

Successfully tested on

Game builds: N/A

Platforms: Windows

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

Fixes #2361

@blattersturm
Copy link
Contributor

Do we have a good outlook on what common data sizes people use are, even in worst-case scenarios? Imposing a total size limit might also help for other scenarios (memory leak spam, e.g.).

The report, of course, rather is an issue with clients submitting data to other clients arbitrarily and it overloading the network layer, for which this fix does appear reasonable.

@AvarianKnight
Copy link
Contributor Author

Do we have a good outlook on what common data sizes people use are, even in worst-case scenarios? Imposing a total size limit might also help for other scenarios (memory leak spam, e.g.).

The common use case for us with state bags is small data, generally only 100 bytes at maximum, except for some global state usage (which is around 200-500 bytes, which still wouldn't get affected by this).

Would be interesting to know other servers general usage.

@AvarianKnight
Copy link
Contributor Author

It should also be noted this is more of a mitigation then an actual fix (though this should have these to prevent spammy attacks anyways).

My idea for fixing

  1. Revert the default to server-side creation as a default
  2. Add a new native to allow for certain state bag names to be created by the client
    A bad name would be something like: AllowClientCreationOfStateBag("key")
  3. Assign protobuf definitions to keys so the server can automatically reject any malformed requests for state bags.

@blattersturm
Copy link
Contributor

blattersturm commented Jan 24, 2024

The third point would be a fairly interesting project for other serialization bits as well - schema validation so there's no 'send an object where a bool is expected'-style replication issues for events that have such an annotation, without having to write manual code validating, while also somehow generating fast validation code.

@FlawwsX
Copy link

FlawwsX commented Jan 24, 2024

Revert the default to server-side creation as a default

I wouldn't expect this to get approved because it would probably break a lot of scripts out there, but some sort of configuration option for server owners to control this would be nice.

@AvarianKnight
Copy link
Contributor Author

Revert the default to server-side creation as a default

I wouldn't expect this to get approved because it would probably break a lot of scripts out there, but some sort of configuration option for server owners to control this would be nice.

When it comes to security vs compat, security should probably be of higher priority.

@AvarianKnight
Copy link
Contributor Author

AvarianKnight commented Jan 24, 2024

FiveM has currently fallen to having most sane defaults behind some 'configuration option' due to maintain compatibility, which means that most of the time the server has to run into the issue before it can actually know that it doesn't have the right default.

This is also very hard to find out for this issue is state bags, as they show as hashes in the timeout log instead of proper packet attribution which was provided here #2141

Changing from server-first creation to client can create all was a massive mistake that I voiced at the time in Discord, but the channels that the conversations were done in were wiped so I can't go back and reference them.

@blattersturm
Copy link
Contributor

blattersturm commented Jan 24, 2024

FiveM has currently fallen to having most sane defaults behind some 'configuration option' due to maintain compatibility

This is what the eventual goal for the original FXv2 effort was, yes - a large watershed point of a few big compat changes that then, if a server runs only FXv2 resources, would put the server in some 'modern' mode which then could be acted upon in e.g. discovery UI in some way to make it a 'desirable' goal for server owners and resoruce authors to work towards.

It however was difficult to coordinate development work towards these changes, so that never really... happened, also as it was meant to be tied with a larger 'FiveM 2' marketing effort with client-side changes and improvements as well, similar to the Windows 10 -> Windows 11 work, where eventually once the work was done the improvements would be lit up for everyone at once, but important platform work could be tested with scoped previews and people manually following the development repo.

Some sort of 'strict mode' or other scoping could make sense as well however (fx_version being replaced with 'editions' and a server being able to run a minimum 'edition' - though how to make sure behavior like this can be tested even in a lower-edition server?), but this'd need a lot of coordination with the resource/asset developer community (or alternative DevRel stuff) in order to get a large portion of the ecosystem on board.

@AvarianKnight AvarianKnight force-pushed the feat/state-bag-limiter branch 3 times, most recently from da78e00 to 8510ded Compare January 25, 2024 13:08
@AvarianKnight AvarianKnight force-pushed the feat/state-bag-limiter branch 3 times, most recently from f73868e to 7a774fe Compare January 26, 2024 11:19
@nihonium-cfx nihonium-cfx self-requested a review January 26, 2024 12:39
* if we accept these willy-nilly, clients could possibly OOM the server, or do a one-to-many make-shift DoS on larger a server
* the size limits here are kept high to keep compatibility with people who "misuse" state bags
* sane defaults for servers that don't send large data via state bags would be `set rateLimiter_stateBagSize_rate 8196` and `set rateLimiter_stateBagSize_burst 16364`
@nihonium-cfx nihonium-cfx added the ready-to-merge This PR is enqueued for merging label Jan 29, 2024
@nihonium-cfx nihonium-cfx merged commit 8aba637 into citizenfx:master Jan 29, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR is enqueued for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lack of state bag rate limiting
4 participants