Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!