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

252
Views
Make POST API Request Without Allowing Other People Access

I am trying to code a website where the user inputs information and it is passed to the backend (node.js/express.js) by the JavaScript. I don't want just anyone to be able to POST the JSON to the server, just the website's code. I am not sure how to do this as I can't use authorisation keys because that would be available as the code is client-side.

The server is using express.js run on node.js and the frontend is just JavaScript triggered from an HTML file.

Any help appreciated!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Short answer: you can't.

Long answer:

Once your API is public on the Internet, everything can connect to it as long as it has network capabilities. Telnet, HTTP, Go program, Node.js scripts, Python scripts, etcetera.

You can limit your API access by using CORS policy, authorization header, user-agent header, referrer header, rate limiter and the like, but it's only a deterrent and everything can be spoofed by a malicious user.

In my opinion, you shouldn't worry about that, really. If you really really want security, and do not want others to access your API, consider implementing a user authentication system with JWT or sessions with secure cookies. It's the best way to protect your endpoints.

Check out these OWASP articles below to learn more about API security.

  • OWASP Top API
  • OWASP Safe REST

If you want to learn more about secure cookies and user authentication in Express, you can check the following articles:

  • Sending Cookies in Express
  • Express Session Management
  • Implementing Secure, HTTPOnly Cookies

I also have one more good article, it's in Go, but you can adapt the concepts in Express.js as well. Here's the link.

about 4 years ago · Juan Pablo Isaza 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!