C
C
cannabioid13372021-07-21 18:43:44
AJAX
cannabioid1337, 2021-07-21 18:43:44

How to secure a file from direct access?

I have a browser JS script on AJAX. In which it refers to the conditional "chat.php", how to make it so that this file cannot be accessed directly, but only through JS?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nadim Zakirov, 2021-07-21
@zkrvndm

Set a password so that access is only possible if a POST request is made with a password.

N
nokimaro, 2021-07-21
@nokimaro

How to disable user access to ajax?

S
Sergey Sokolov, 2021-07-21
@sergiks

A few ideas, as they get more complex:

  1. Leave this thing. Everything that is somehow transmitted to the browser can be received bypassing the developer's intent.
  2. Go to HTTP POST request. With a GET request of the same URL (opened directly in the browser /chat.php- return a stub, or, better, a redirect to the main.
  3. When accessed from JS, add an HTTP header. To chat.phpcheck for its presence.
  4. When loading a page, create-transmit a unique session identifier from the server. Use it in the header of ajax requests and check inchat.php
  5. Switch to WebSocket: after all, the chat should be in real time)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question