godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Separate HTML5 User App Data by game instead of domain #2207

Open Algorithmus opened 3 years ago

Algorithmus commented 3 years ago

Describe the project you are working on

HTML5 game, has saving/loading features.

Describe the problem or limitation you are having in your project

The user app data in Godot HTML5 games are shared across games in the same domain. This affects games that are hosted in the same place like itch.io, and may cause user app data to become corrupted because they're normally not supposed to be shared between games like they aren't in binary builds. You can look at the indexed DB section of the browser's inspector tools of another HTML5 Godot game to see that all the files that shows up there are not separated. If you save something in user://saves/abc.json from one HTML5 game in Godot and play another HTML5 Godot game in the same browser, same domain, you'll be able to access that same file with the same path.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

User app data in HTML5 should be separated by the game they're from. Then I won't be able to access user app data from another game that happens to be hosted on itch.io, and the other games won't be able to affect user app data in my game either when hosted on itch.io.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Perhaps instead of mapping user:// with userfs/ in indexedDB, it should be saved under userfs/[name of game] like it works in binary builds: /.local/share/godot/app_userdata/[name of game]

If this enhancement will not be used often, can it be worked around with a few lines of script?

Well sure, I could just choose to save all my data under user://[name of game] but this is redundant for binary builds, and it's not properly documented if it is this way by design.

Is there a reason why this should be core and not an add-on in the asset library?

This is a security vulnerability for users who upload games to game hosting sites like itch.io because you should be able to reasonably expect your user app data should not be corrupted by another game on the same domain.

Faless commented 3 years ago

Perhaps instead of mapping user:// with userfs/ in indexedDB, it should be saved under userfs/[name of game] like it works in binary builds: /.local/share/godot/app_userdata/[name of game]

I agree, but this will be a breaking change, and user will lose their data. So it will have to wait 4.0

dsnopek commented 3 years ago

I agree, but this will be a breaking change, and user will lose their data. So it will have to wait 4.0

Could it maybe be an opt-in export configuration variable in 3.2? By default, it would be off to not break compatibility, but if enabled would be used in the exported game -- something like that?

Calinou commented 3 years ago

Could it maybe be an opt-in export configuration variable in 3.2? By default, it would be off to not break compatibility, but if enabled would be used in the exported game -- something like that?

I think it's better to namespace all your user files to a folder to achieve this for now.