3
I am in the development of a web application, which would be necessary in some cases to make available in HTML (for JS to interact) ID of user posts, ID of comments and others...
Example:
<div id="cmt_IDDOCOMENTARIO" class="comment-text">
Comentário......
</div>
The question is... I have concerns about providing information that the user should not have access to, especially the ID of results obtained in the bank.
How can I "encrypt" this type of information, to prevent possible attacks, intrusions and etc?
I’ve been studying how Facebook does it, but I can’t find basically anything on the Web about.
Note: Who is interested in the site, still under development: http://schedy.inventeweb.com.br/login
In the applications that I worked with, the id is only and exclusively for relationship control but as control of internal information, for example to make an update in the bank. Never hear the need to "show" a PK. What would be your need?
– gabrielfalieri
When I need to use the data in the view in this way, I usually associate it with an html element. For example, in tr I assign an ID in the rendering, this id I can use in JS. If you need to create an additional attribute, it is also possible, such as data-pk=$id.
– David Dias
Whether it’s safe or not, I honestly don’t see the need to have this fear. These negotiations are solved with session token, authentication middleware, etc.
– David Dias
I updated the publication by citing an example.
– Rodrigo Roberto de Almeida
I understand, but using JS data-tags would still not be making ID/PK available for source code? I mean... Assuming the ID in the database is 123, the html would not be:. <div id="cmt" class="comment" date-id="123"> Text </div> Continuing to be "explicit" ?
– Rodrigo Roberto de Almeida
Yes, it will. Explain. I don’t have as much information to make you safe that this is not a bad practice, however, I see in several systems this and use so, I believe that there is no problem to do this, as long as you are sure about the negotiations in the backend. Quick thinking, an alternative, would be a reference in HTML that, through an API (token, magic logic, I don’t know) return the PK for you to use.
– David Dias
But, I honestly don’t understand why you want FK in the view. An example about my uses: In Model I deal with Fks. In this way, consider that everything is solved through the methods already defined that abstract the calls, like: User, Comments. Users have comments. Comments belong to User. That way, you don’t need to pass the FK, just the comment ID, for example. By accessing the user’s comments, you will have the specific comment by the ID. .
– David Dias