The safest way to do this, is to have the game rules on the server. You read input from the client, you render on the client, but the simulation that matters is on the server.
(For action games, you may need to ALSO run the simulation on the client, and then fix it up if the server tells the client that the outcome was different than what the client simulated.)
If that's not doable for you, then you can also send a stream of moves/actions for the game to the server as they happen, perhaps with incremental scores, and when the game finishes, if the player got a significantly high score, OR randomly once in a while, play back the recorded game on the server, and verify that the output was as stated.
The third option is to realize that this game isn't all that important in the world, a cheater is unlikely to actually show up for a while, and maybe it's OK with a leaderboard that's easy-ish to cheat. You could at least make the key be different per player (assuming you have player registration,) so that the same player cheat code that works for player A, works for player B without some changes. That might cut down on the cheesiest and simplest scripts. But probably not.