Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can a user modify remove a `defer` tag of a script that redirects them

I have a <script> in the <head> of an HTML file that checks to see if the user is authorized to view the page’s contents through a token cookie. The <script> is tagged with defer and immediately redirects the user if they are not authorized. Would a user or a bot be able to remove the defer tag and allow the page to load? Is there a better way to ensure a user is authorized before the page loads?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A user can absolutely bypass your mechanism. Likely in less than 30 seconds. You should never, ever, and I mean never, use the client side to be sure whether the client is logged in. Let’s say the user simply disables JavaScript. No more redirection. Because the code is run on the user’s computer, they can modify the code however they want.

The correct way (in your specific situation, things get different in other approaches) to do this is from the server. Use session, JWT, or some other auth mechanism, from the server. Redirect your client from the server. Only send data to the user if they are logged in.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading