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

111
Views
Safe way to get origin

I am maintaining an application in which I access the origin via window.origin in order to build some URLs.

It works... but I had a security alert because it seems that this variable can be written. For example, go on Google and try that in the dev tools :

> window.origin
<   'https://www.google.com'
> window.origin='yolo'
<   'yolo'
> window.origin
<   'yolo'

This is indeed a security issue as my URLs are built like this : window.origin + "/path/to/other/app" If an attacker could find a way to execute this script window.origin = 'evil.com', customers would be redirected to an unexpected URL.

I found that I could call location.origin instead, which seems safer :

> location.origin
<   'https://www.google.com'
> location.origin='yolo'
<   'yolo'
> location.origin
<   'https://www.google.com'

But does it work on every browser ? Is there a recommended way of getting the origin ?

about 4 years ago · Santiago Gelvez
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!