curious about the use of GET requests for player actions

Game development with Board Game Arena Studio
User avatar
robinzig
Posts: 461
Joined: 11 February 2021, 18:23

curious about the use of GET requests for player actions

Post by robinzig »

I'm a moderately experienced web developer (3-4 years' experience) just getting started with the BGA framework, and I've noticed something about how it works that seems strange to me. I'm well aware it's probably too late to change things but I'm just curious about the thinking behind why it's this way in the first place.

What puzzles me is that the Ajax requests that are sent when a player takes an action are GET requests, rather than POST or any other method - despite the fact that they almost always lead to changes in the game database. This is certainly against REST principles - although perhaps that's mostly academic here. One of the biggest arguments against state-changing GET requests is that search engine crawlers, or humans who can be persuaded to click on links etc, will unexpectedly cause these state-changing actions - but given that the URLs for BGA player actions are not linked anywhere, and rely on particular query parameters as well as being dependent on game state and so on, it seems hugely unlikely that any incident could occur that ruins a game. Although not impossible - if I'm in a turn-based game and I want to cheat, and know an opponent will take a few days over their next turn, I could in theory figure out what the URL would be for some particular catastrophically stupid move they could in theory make, and do some social engineering attack to get them to trigger that link. Actually, does the server even check that there is a user making the request that matches the user ID in the URL? If not a cheat could "make moves" for their opponents all by themselves! :shock: But I'm sure there are at least some session cookies or similar involved - at least I hope so!

One other inconvenience of the GET request method is that it becomes hard to send structured data as part of a game action. In a POST request one could easily send a JSON body of arbitrary complexity. In theory a GET request could do the same by sending a JSON string as a query value - but this isn't' something that's really often done, and in any case wouldn't work in the BGA framework because the "action methods" only accept certain particular formats of data (for anti-cheating reasons, I suppose). I've already been struck with how awkward it is to send something simple like a list of card IDs to be discarded - you have to put all the IDs in a single comma-separated string, which admittedly isn't at all difficult but it becomes quite a bit of "boilerplate" to encode Javascript arrays this way on the client side then decode them to PHP arrays on the server side. And the complete inability to send more complex data like an array of objects (yes it could be done via JSON encoding/decoding but it feels like this would be discouraged, and you'd have to come up with your own validation on the server side to ensure the data is well-formed) also seems like a frustrating limitation.

Am I alone in feeling that this is all far from ideal? And are there good reasons it has to be this way, or is it just one of those historical accidents that came about and we're just now stuck with it because it would break too much to change it? (I expect it is, but I'd be interested to hear if there's more to the story.)

Thanks for indulging my question :)
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: curious about the use of GET requests for player actions

Post by Tisaac »

robinzig wrote: 18 May 2021, 15:30 I'm a moderately experienced web developer (3-4 years' experience) just getting started with the BGA framework, and I've noticed something about how it works that seems strange to me. I'm well aware it's probably too late to change things but I'm just curious about the thinking behind why it's this way in the first place.

What puzzles me is that the Ajax requests that are sent when a player takes an action are GET requests, rather than POST or any other method - despite the fact that they almost always lead to changes in the game database. This is certainly against REST principles - although perhaps that's mostly academic here. One of the biggest arguments against state-changing GET requests is that search engine crawlers, or humans who can be persuaded to click on links etc, will unexpectedly cause these state-changing actions - but given that the URLs for BGA player actions are not linked anywhere, and rely on particular query parameters as well as being dependent on game state and so on, it seems hugely unlikely that any incident could occur that ruins a game. Although not impossible - if I'm in a turn-based game and I want to cheat, and know an opponent will take a few days over their next turn, I could in theory figure out what the URL would be for some particular catastrophically stupid move they could in theory make, and do some social engineering attack to get them to trigger that link. Actually, does the server even check that there is a user making the request that matches the user ID in the URL? If not a cheat could "make moves" for their opponents all by themselves! :shock: But I'm sure there are at least some session cookies or similar involved - at least I hope so!

One other inconvenience of the GET request method is that it becomes hard to send structured data as part of a game action. In a POST request one could easily send a JSON body of arbitrary complexity. In theory a GET request could do the same by sending a JSON string as a query value - but this isn't' something that's really often done, and in any case wouldn't work in the BGA framework because the "action methods" only accept certain particular formats of data (for anti-cheating reasons, I suppose). I've already been struck with how awkward it is to send something simple like a list of card IDs to be discarded - you have to put all the IDs in a single comma-separated string, which admittedly isn't at all difficult but it becomes quite a bit of "boilerplate" to encode Javascript arrays this way on the client side then decode them to PHP arrays on the server side. And the complete inability to send more complex data like an array of objects (yes it could be done via JSON encoding/decoding but it feels like this would be discouraged, and you'd have to come up with your own validation on the server side to ensure the data is well-formed) also seems like a frustrating limitation.

Am I alone in feeling that this is all far from ideal? And are there good reasons it has to be this way, or is it just one of those historical accidents that came about and we're just now stuck with it because it would break too much to change it? (I expect it is, but I'd be interested to hear if there's more to the story.)

Thanks for indulging my question :)
You can send and receive json with bga framework already.
User avatar
thoun
Posts: 1621
Joined: 10 December 2020, 22:25

Re: curious about the use of GET requests for player actions

Post by thoun »

Really ? It's not written in the doc, available types are limited. I encoded to base64 my Json, not knowing it is possible with framework. If someday you have the time to add this to the studio doc, it might help others :)
User avatar
Woodruff
Posts: 423
Joined: 08 March 2014, 00:53

Re: curious about the use of GET requests for player actions

Post by Woodruff »

As we say between developpers, RTFM :D
(no offense meant here)

It is documented here:
https://fr.studio.boardgamearena.com/do ... yers_input
--> this.ajaxcall
This handles JSON format (named parameters) by default.

This enables you to link the client to the php handler for entry points, which is described here:
https://fr.studio.boardgamearena.com/do ... action.php

Have a nice dev :)
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: curious about the use of GET requests for player actions

Post by Tisaac »

thoun wrote: 18 May 2021, 18:09 Really ? It's not written in the doc, available types are limited. I encoded to base64 my Json, not knowing it is possible with framework. If someday you have the time to add this to the studio doc, it might help others :)
Yeah I will add it
User avatar
robinzig
Posts: 461
Joined: 11 February 2021, 18:23

Re: curious about the use of GET requests for player actions

Post by robinzig »

Woodruff wrote: 18 May 2021, 18:43 As we say between developpers, RTFM :D
(no offense meant here)

It is documented here:
https://fr.studio.boardgamearena.com/do ... yers_input
--> this.ajaxcall
This handles JSON format (named parameters) by default.

This enables you to link the client to the php handler for entry points, which is described here:
https://fr.studio.boardgamearena.com/do ... action.php

Have a nice dev :)
Thanks, but this doesn't seem to be in the English docs (I didn't even realise there were separate French ones). The equivalent section https://en.doc.boardgamearena.com/Game_ ... yers_input doesn't mention JSON, and indeed searching for "json" on the entire page reveals no matches.

And the page where it talks about the various different input types you can use (https://en.doc.boardgamearena.com/Playe ... on_methods) also doesn't mention this - and we're told how important it is to use one of these types to validate the input. There's no obvious way to fit JSON into this framework (given that it includes characters like double quotes and curly braces) other than base64, as @thoun mentioned - which I must say I didn't really consider as it seems, well, weird. (To me base64 is to encode binary data, not text :) )

So, and I say this nicely in response to your "no offense meant", please don't tell me to RTFM when I already have, several times :) [I'm one of those developers who gets annoyed at reading questions, eg on Stack Overflow, from people who clearly have never done that for whatever language/framework they're asking about! :D ]

In any event, I posted this not to ask for help in development - although I certainly welcome such. It was more about: why does BGA use the GET method for things that update the database, which is against all REST principles? And does this not open the door to cheaters via, at the least, CSRF attacks?
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: curious about the use of GET requests for player actions

Post by Tisaac »

thoun wrote: 18 May 2021, 18:09 Really ? It's not written in the doc, available types are limited. I encoded to base64 my Json, not knowing it is possible with framework. If someday you have the time to add this to the studio doc, it might help others :)
Here you go, it's documented here now : https://en.doc.boardgamearena.com/Playe ... action.php
robinzig wrote: 18 May 2021, 19:25 In any event, I posted this not to ask for help in development - although I certainly welcome such. It was more about: why does BGA use the GET method for things that update the database, which is against all REST principles? And does this not open the door to cheaters via, at the least, CSRF attacks?
I think they have a way to check that the player sending the action is the one being authentified in the corresponding session, so no cheating possible.
And honestly I don't really care if they use GET or POST as long as I'm not restricted in my dev possibilities by that choice, which it is not the case until then.
But other specialists might have more insights than me on this topic :)
User avatar
Benoit314
Posts: 82
Joined: 02 April 2020, 22:12

Re: curious about the use of GET requests for player actions

Post by Benoit314 »

robinzig wrote: 18 May 2021, 19:25 In any event, I posted this not to ask for help in development - although I certainly welcome such. It was more about: why does BGA use the GET method for things that update the database, which is against all REST principles? And does this not open the door to cheaters via, at the least, CSRF attacks?
I think it is an interesting question. It is also kind of easy to check.
What might have happened it that often you only have a small window to do a specific game action. So it is kind of hard to cheat in that timeframe. But what about table actions like abandon or change settings?
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: curious about the use of GET requests for player actions

Post by Victoria_La »

There is really a french wiki for docs???
Json is not documented on purpose because devs do not add enought security to validate random input and it will be sql injections and xss right left and. center (same for bas64) .
I sent bug to studio to have public stricter json API (that is string are validated to be alphanum or similar) and then it can be made public.
User avatar
robinzig
Posts: 461
Joined: 11 February 2021, 18:23

Re: curious about the use of GET requests for player actions

Post by robinzig »

Victoria_La wrote: 19 May 2021, 02:12 There is really a french wiki for docs???
I guess not :) I just got confused because @Woodruff's post had a link to a site starting "fr" whereas the wiki pages I use have URLs starting "en". (And I know a lot of BGA users and the original developers are French-speaking so it made sense to me that French docs might exist.) I didn't actually look because I got a browser warning that the site isn't secure :o and didn't fancy last night taking the extra clicks to see the page. I just did that now (of course https doesn't actually matter if you're just reading stuff!) and see the text is in English too. But I don't know why the 2 different URLs for the same docs in the same language, and if there are any actual differences in content.
Json is not documented on purpose because devs do not add enought security to validate random input and it will be sql injections and xss right left and. center (same for bas64) .
I sent bug to studio to have public stricter json API (that is string are validated to be alphanum or similar) and then it can be made public.
I understand the security concerns - that's what I assumed to start with. Thanks for doing this. (I probably won't actually use JSON unless I come across a situation which I feel really calls out for it, but it's nice to know the option is there.)
Post Reply

Return to “Developers”