Skip to content

fix: migrar Firebase v8 → v12 API modular (CVE GHSA-3wf4-68gx-mph8)#7

Open
gonzafg2 wants to merge 1 commit into
masterfrom
fix/firebase-v12-modular
Open

fix: migrar Firebase v8 → v12 API modular (CVE GHSA-3wf4-68gx-mph8)#7
gonzafg2 wants to merge 1 commit into
masterfrom
fix/firebase-v12-modular

Conversation

@gonzafg2
Copy link
Copy Markdown
Owner

Resumen

  • Migra Firebase de v8 (API namespace/compat) a v12 (API modular) resolviendo el CVE GHSA-3wf4-68gx-mph8 (manipulación de _authTokenSyncURL en firebase < 10.9.0)
  • Convierte todos los accesos a Firestore a la API modular — sin compat layer
  • Build y lint verificados sin errores

Archivos cambiados

  • package.json / package-lock.json: firebase@8.10.1firebase@^12.0.0
  • src/boot/firebase.js: reemplaza imports de namespace (import firebase from "firebase/app") por API modular (initializeApp, getFirestore, getPerformance); ya no exporta el objeto firebase, solo db
  • src/pages/Index.vue: convierte todas las llamadas compat a modular:
    • db.collection("x").get()getDocs(collection(db, "x"))
    • db.collection("x").add({...})addDoc(collection(db, "x"), {...})
    • db.collection("x").doc(id).update({...})updateDoc(doc(db, "x", id), {...})
    • db.collection("x").doc(id).delete()deleteDoc(doc(db, "x", id))
    • firebase.firestore.FieldValue.serverTimestamp()serverTimestamp()

CVE resuelto

GHSA-3wf4-68gx-mph8 — Moderate severity, afecta firebase < 10.9.0. Permite manipulación de _authTokenSyncURL en la SDK cliente. Resuelto actualizando a v12.

Test plan

  • npm run build — compilación exitosa sin warnings de Firebase
  • npm run lint — sin errores de ESLint
  • Verificar en browser: carga de inventario, entrada/salida de stock, eliminación de productos

)

- Reemplaza imports de namespace (firebase/app compat) por API modular de Firebase v12
- src/boot/firebase.js: usa initializeApp, getFirestore, getPerformance
- src/pages/Index.vue: convierte todos los db.collection() a collection/getDocs/addDoc/updateDoc/deleteDoc
- serverTimestamp() reemplaza firebase.firestore.FieldValue.serverTimestamp()
- Ya no se exporta el objeto firebase desde el boot — solo db
- Build y lint verificados sin errores
Copilot AI review requested due to automatic review settings April 15, 2026 23:29
@github-actions
Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 79fc30b):

https://stock-kipreos--pr7-fix-firebase-v12-mod-mpiavuo5.web.app

(expires Wed, 22 Apr 2026 23:30:03 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f6494f73a94ac2a024c9044507ced3bba7960b54

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Este PR migra el uso de Firebase/Firestore desde la API namespace/compat (v8) a la API modular (v12), con el objetivo de eliminar el vector del CVE reportado y modernizar el acceso a Firestore en el frontend.

Changes:

  • Actualiza la dependencia firebase a ^12.12.0.
  • Refactoriza el bootstrap de Firebase para inicializar con initializeApp() y exponer db vía getFirestore().
  • Migra las operaciones CRUD de Firestore en Index.vue a getDocs/addDoc/updateDoc/deleteDoc y serverTimestamp().

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.

File Description
package.json Bump de firebase a v12.x para resolver el CVE y habilitar API modular.
package-lock.json Actualiza el árbol de dependencias acorde a Firebase v12.x.
src/boot/firebase.js Inicialización modular de Firebase (app, Firestore, Performance) y export de db.
src/pages/Index.vue Reemplazo de llamadas compat (db.collection()...) por funciones modulares de Firestore.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/Index.vue
Comment on lines 2274 to 2278
const importBigData = bigdata.forEach(async set => {
const query = await db.collection("productos").add(set);
const query = await addDoc(collection(db, "productos"), set);

await this.data.push({
id: set.id,
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En importTable, bigdata.forEach(async ...) no se espera, por lo que la importación puede seguir (y notificar éxito) sin que hayan terminado los addDoc, y los errores dentro del callback no llegan al try/catch. Conviene construir un array de Promises y await Promise.all(...) o iterar con for...of y await.

Copilot uses AI. Check for mistakes.
Comment thread src/pages/Index.vue
Comment on lines +1258 to 1261
const query = await getDocs(collection(db, "productos"));

// query es un objeto de más objetos, por lo que hay que transformarlo a un arreglo de objetos.
await query.forEach(elemento => {
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QuerySnapshot.forEach(...) es síncrono (no devuelve Promise). En esta sección el await previo al forEach no tiene efecto y puede dar una falsa sensación de que se están esperando operaciones dentro del loop. Quitar el await o usar un for...of si necesitás await dentro del recorrido.

Copilot uses AI. Check for mistakes.
Comment thread src/boot/firebase.js

var db = firebaseApp.firestore();
const firebaseApp = initializeApp(firebaseConfig);
const perf = getPerformance(firebaseApp);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perf se declara pero no se usa en el archivo. Si la intención es solo inicializar Performance Monitoring por side-effect, puede evitarse la variable (p. ej. evaluar la llamada sin asignar) o agregar un comentario explicando por qué se mantiene, para no dejar un símbolo aparentemente “muerto”.

Suggested change
const perf = getPerformance(firebaseApp);
// Inicializa Performance Monitoring por side-effect.
getPerformance(firebaseApp);

Copilot uses AI. Check for mistakes.
Comment thread src/pages/Index.vue
.update({
stock: stockSuma
});
updateDoc(doc(db, "productos", idSelInput), {
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En saveAddInput, la llamada a updateDoc(...) no se espera (await). Si falla el update de stock, el try/catch no lo va a capturar y la UI puede notificar éxito igualmente. Conviene await updateDoc(...) (o manejar explícitamente el Promise) antes de continuar.

Suggested change
updateDoc(doc(db, "productos", idSelInput), {
await updateDoc(doc(db, "productos", idSelInput), {

Copilot uses AI. Check for mistakes.
Comment thread src/pages/Index.vue
.update({
stock: stockResta
});
updateDoc(doc(db, "productos", idSelOutput), {
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En saveAddOutput, la llamada a updateDoc(...) no se espera (await). Si el update de stock falla, el error no se captura por el try/catch y se puede mostrar la notificación de éxito igual. Debería esperarse el update o manejar el Promise.

Suggested change
updateDoc(doc(db, "productos", idSelOutput), {
await updateDoc(doc(db, "productos", idSelOutput), {

Copilot uses AI. Check for mistakes.
Comment thread src/pages/Index.vue
Comment on lines 2143 to 2147
let idArray = this.selected
.map(el => el.id)
.forEach(async id => {
const query = await db
.collection("productos")
.doc(id)
.delete();
await deleteDoc(doc(db, "productos", id));
});
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En deleteSelected, se usa .forEach(async ...) sobre los IDs y no se espera el resultado. Los errores dentro del callback no van a ser capturados por el try/catch y además el flujo continúa (borrado local + notificación) antes de que terminen los deletes remotos. Usar await Promise.all(ids.map(id => deleteDoc(...))) o un for...of con await.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants