Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda