Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
How to restrict API's to run only in the browser?

I am using node js and i put polices to restrict the api's accurance otherthan in browser.For that i put the following condition

app.route('/students').all(policy.checkHeader).get(courses.list)

exports.checkHeader =  function(req, res, next) {
    var headers = req.headers;
       if ( headers['upgrade-insecure-requests'] || headers['postman-token']) {
        res.status(401).json('Page not found');
    } else {
        return next();
    }

}

I am not sure whether my process is correct.I am searching for the common parameter(header-parameter) that exists only for the browser.Can anyone please help me.Thanks.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This is impossible.

You can't control what types of clients make HTTP requests to your HTTP server.

You can't reliably identify what type of client has made a request you receive.

An upgrade-insecure-requests header can be sent (or not sent) with any value by any custom client. Ditto postman-token. Ditto user-agent. Ditto everything else.

The only way to restrict it would be to require some kind of secret in the request. If you want regular web browsers to access it, then the secret will leak through the browser developer tools.

about 4 years ago · Santiago Trujillo Denunciar

0

I don't think it's possible to really block the requests without Authentication / Authorization. However, you can use the HTTP Header's User-Agent field

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda