@opensas/xml-rest-adapter 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/request-to-xml.js +13 -1
- package/package.json +1 -1
package/dist/request-to-xml.js
CHANGED
|
@@ -27,6 +27,16 @@ const getXmlOrden = (orden) => orden
|
|
|
27
27
|
})
|
|
28
28
|
.join(',');
|
|
29
29
|
const IDENTIFICADOR_SQL = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
30
|
+
// ORDER BY posicional ("_order=1" → columna 1 del select) — solo dígitos, no hay forma de
|
|
31
|
+
// convertir esto en nada más que un entero literal.
|
|
32
|
+
const POSICION_SQL = /^[0-9]+$/;
|
|
33
|
+
// count(*)/min(Columna)/max(Columna), con alias obligatorio — no es una apertura genérica a
|
|
34
|
+
// "cualquier función SQL": la lista de funciones es fija (las que consumidores reales necesitan
|
|
35
|
+
// hoy, ver docs/casos-de-uso-campos-orden.md) y el argumento solo puede ser '*' o un identificador
|
|
36
|
+
// bare — nada de subconsultas, operadores ni paréntesis anidados. Generaliza como grámatica
|
|
37
|
+
// verificable la excepción puntual que ya existía para el literal interno 'Count(*) as count'
|
|
38
|
+
// (ver comentario de execXmlConsulta en db.ts).
|
|
39
|
+
const AGREGADO_SQL = /^(count|min|max)\(\s*(\*|[A-Za-z_][A-Za-z0-9_]*)\s*\)\s+[A-Za-z_][A-Za-z0-9_]*$/i;
|
|
30
40
|
// Defensa en profundidad — espejo de dbo.esListaDeCampos (docker/fixture/scripts/02-support.sql,
|
|
31
41
|
// ver también docs/todos/sql-injection-campos-orden.md en convenios_web). La capa autoritativa es
|
|
32
42
|
// esa función en SQL Server: cubre también a los consumidores legacy (apps ASP clásico) que le
|
|
@@ -43,13 +53,15 @@ function esListaDeCampos(lista, permiteAscDesc) {
|
|
|
43
53
|
const campo = item.trim();
|
|
44
54
|
if (campo === '')
|
|
45
55
|
return false;
|
|
56
|
+
if (AGREGADO_SQL.test(campo))
|
|
57
|
+
return true;
|
|
46
58
|
if (!permiteAscDesc)
|
|
47
59
|
return IDENTIFICADOR_SQL.test(campo);
|
|
48
60
|
const partes = campo.split(/\s+/);
|
|
49
61
|
if (partes.length > 2)
|
|
50
62
|
return false;
|
|
51
63
|
const [nombre, direccion] = partes;
|
|
52
|
-
if (!IDENTIFICADOR_SQL.test(nombre))
|
|
64
|
+
if (!IDENTIFICADOR_SQL.test(nombre) && !POSICION_SQL.test(nombre))
|
|
53
65
|
return false;
|
|
54
66
|
return direccion === undefined || ['ASC', 'DESC'].includes(direccion.toUpperCase());
|
|
55
67
|
});
|