23

I'm a little bit of an amateur on API security. I'm building a browser-based puzzle with a leaderboard, and I'm wondering what prevents a user from simply hitting the /success endpoint with data that basically equates to { time: '3s' } automatically putting them at the top of the leaderboard without even actually finishing the puzzle.

If they just fetch from the console, what's to stop them from falsifying their result? The headers can all be faked to look authentic, right? And from the console it would still be "coming from your webpage" so it would pass a whitelist. So how is this handled?

temporary_user_name
  • 812
  • 1
  • 9
  • 17
  • 32
    Never trust a client you don't have sufficient control over, which basically means never trust a something running in the clients browser even if you hope that this is your app. Does this answer your question? Is it possible to ensure client data is correct? – Steffen Ullrich Mar 01 '24 at 06:57
  • 17
    Remember; The UI of your website is an entirely optional way for users to interact with your APIs. If they want to use any other front end that's fine. Believing anything else will lead to security disasters – Richard Tingle Mar 01 '24 at 16:18
  • 2
  • Your users are authenticated with some sort of credentials, right? 2. Authenticated users cannot just post scores, the server knows what time the game started, and the /success endpoint just subtracts now from the start time to calculate how long the game took. It's now impossible for a user to fake how long a game took.
  • – Neil Mar 01 '24 at 16:55
  • 17
    Nothing stops them. In fact nothings stops them from hitting your endpoint with arbitrary data without the use of your webpage code. – Bergi Mar 01 '24 at 17:04
  • 14
    You have good thinking skills to ask this question. You're going to do well in security. – Wayne Conrad Mar 01 '24 at 17:14
  • 1
    And it doesn't even need to be from the browser console. You can use Postman, Fiddler, or any other tool - even write your own. As long as you can send HTTP requests (which is trivial in most programming languages today), you're good to go! – Vilx- Mar 03 '24 at 12:48
  • 1
    @Vilx-: I think the point of stressing the *browser console" part is that, as opposed to the other options, it can be particularly effortless from there: Depending on the framework used, you may be able to directly use the pre-configured HTTP client of the web app that already attaches all the required headers (auth header etc.) by default, so you don't even have to think about or look at what the original message looks like beyond the URL and body. – O. R. Mapper Mar 03 '24 at 23:37