So I have an iOS app written in Swift that communicates with a node.js server with an SQL database behind it. The app uses database IDs to retrieve objects from the database. So a search feature on the app will return an array of IDs and the app requests the object data from the server using those IDs of the objects it needs.
The IDs correspond to an auto-incrementing primary key integer in the objects table, for example:
CREATE TABLE database.events (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
description VARCHAR(1000) NOT NULL
);
From what I've seen some people think this is an awful thing to do and others say if done correctly this shouldn't be a problem. I think in my instance the latter is what I agree with. By 'thing' I mean exposing database IDs to the frontend (the client app).
My understanding is there can be 2 main issues with this:
- If a hacker exploited the app and figured out how it makes requests to the server they could send malicious requests requesting data that they should not be allowed to see.
- Auto-incrementing IDs can reveal user count, information about the number of clients and customers the business may have.
Am I right in these being the only real issues with it?
For the first one I've put the necessary checks in (server-side) to make sure that a user cannot request or gain access to data they do not have permission to view.
For the second issue, and this I guess is more of why I'm posting this question is how to deal with this elegantly. Admittedly it isn't as bad as the IDs being exposed in a URL as with the app it would require hacking the app to view the data it is sending and receiving. However I still consider that to be an issue and do wish to obscure IDs to stop anyone potential gaining information mentioned above from the IDs.
I was thinking of creating a kind of hashed ID from the auto-incrementing IDs initially from using hash-id but they recommended using Optimus if you only want to generate numerical IDs which I would prefer. It would then be this hashed ID that the app client would use to request objects from the server.
My question is, is this a rational and elegant solution? Is there a better way? Or have I missed a critical vulnerability that I am creating from doing any of this?