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

268
Views
Extensión de Chrome: Realización de una solicitud http a un servidor node.js que envía credenciales de cookies (CORS)

He tenido algunos problemas con mi servidor node.js. Lo lancé usando heroku y ahora quiero que mi extensión de Chrome envíe solicitudes http al servidor (usando cookies).

Estoy usando express.js como backend y tengo problemas para configurar CORS de la manera correcta.

Esto es lo que tengo en app.js:

 if (process.env.NODE_ENV !== 'production') { app.use(cors({ credentials: true, origin: ['http://localhost:4200', 'http://localhost:8000', 'chrome-extension://kdfekbilmpafgiocanhihiogknfilcio'] })); } else { app.use(cors({ credentials: true, origin: ['chrome-extension://kdfekbilmpafgiocanhihiogknfilcio'] })); } app.use(session({ secret: 'angular shhh secret auth', resave: true, saveUninitialized: true, cookie : { httpOnly: true, expires: new Date(253402300000000) } }));

y estoy haciendo solicitudes de mi extensión de Chrome (cliente) como esta:

 signUp(user) { const options = { withCredentials: true }; return this.myHttp.post(`${this.BASE_URL}/signup`, user, options) .toPromise() .then((result) => { result.json() }); }

Y este es mi error:

 XMLHttpRequest cannot load https://moodflowextension.herokuapp.com/loggedin. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:4200' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

Sé que debería pasar la cookie en el encabezado de alguna manera...

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Las sesiones y las credenciales requieren una mayor seguridad en la forma de no tener comodines en su encabezado.

Afortunadamente, hay una forma de evitar esto.

var whitelist = [/yourDomain/]; var corsOptions = { origin: whitelist }; app.use(cors(corsOptions));

Esto hará que CORS solo permita orígenes que contengan su Dominio (que es una expresión regular por cierto, no una cadena), sin interrumpir las credenciales y las sesiones.

over 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!