Skip to content

Commit d286f51

Browse files
committed
Flip UNSAFE label to SAFE and fix/remove impossible cases
1. These are now deemed safe (for now), so flip the labels. 2. Some cases are impossible: `entries` call only accepts only objects (as varargs or an array of them). So, if it can be fixed, then fix it; otherwise, remove it.
1 parent 7a2db7b commit d286f51

File tree

1 file changed

+42
-48
lines changed
  • javascript/frameworks/cap/test/queries/cqlinjection/srv

1 file changed

+42
-48
lines changed

javascript/frameworks/cap/test/queries/cqlinjection/srv/service1.js

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ module.exports = class Service1 extends cds.ApplicationService {
5555

5656
this.on("send00131", async (req) => {
5757
const { id } = req.data;
58-
cds.create("Entity1").entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
58+
cds.create("Entity1").entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
5959
});
6060

6161
this.on("send00132", async (req) => {
6262
const { id } = req.data;
63-
cds.create("Entity1").entries({id: `` + id}); // UNSAFE: direct concatenation with `+`
63+
cds.create("Entity1").entries({id: `` + id}); // SAFE: `entries` call safely parses the property value
6464
});
6565

6666
this.on("send00133", async (req) => {
6767
const { id } = req.data;
68-
cds.create("Entity1").entries({id: `${id}`}); // UNSAFE: direct interpolation in a template literal
68+
cds.create("Entity1").entries({id: `${id}`}); // SAFE: `entries` call safely parses the property value
6969
});
7070

7171
this.on("send00141", async (req) => {
@@ -90,32 +90,32 @@ module.exports = class Service1 extends cds.ApplicationService {
9090

9191
this.on("send00151", async (req) => {
9292
const { id } = req.data;
93-
cds.insert("Entity1").entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
93+
cds.insert("Entity1").entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
9494
});
9595

9696
this.on("send00152", async (req) => {
9797
const { id } = req.data;
98-
cds.insert("Entity1").entries({id: `` + id}); // UNSAFE: direct concatenation with `+`
98+
cds.insert("Entity1").entries({id: `` + id}); // SAFE: `entries` call safely parses the property value
9999
});
100100

101101
this.on("send00153", async (req) => {
102102
const { id } = req.data;
103-
cds.insert("Entity1").entries({id: `${id}`}); // UNSAFE: direct interpolation in a template literal
103+
cds.insert("Entity1").entries({id: `${id}`}); // SAFE: `entries` call safely parses the property value
104104
});
105105

106106
this.on("send00161", async (req) => {
107107
const { id } = req.data;
108-
cds.upsert("Entity1").entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
108+
cds.upsert("Entity1").entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
109109
});
110110

111111
this.on("send00162", async (req) => {
112112
const { id } = req.data;
113-
cds.upsert("Entity1").entries({id: `` + id}); // UNSAFE: direct concatenation with `+`
113+
cds.upsert("Entity1").entries({id: `` + id}); // SAFE: `entries` call safely parses the property value
114114
});
115115

116116
this.on("send00163", async (req) => {
117117
const { id } = req.data;
118-
cds.upsert("Entity1").entries({id: `${id}`}); // UNSAFE: direct interpolation in a template literal
118+
cds.upsert("Entity1").entries({id: `${id}`}); // SAFE: `entries` call safely parses the property value
119119
});
120120

121121
this.on("send00171", async (req) => {
@@ -166,25 +166,19 @@ module.exports = class Service1 extends cds.ApplicationService {
166166
this.on("send00221", async (req) => {
167167
const { id } = req.data;
168168
const { Service1Entity } = this.entities;
169-
await INSERT.into(Service1Entity).entries("ID =" + id); // UNSAFE: direct concatenation with `+`
169+
await INSERT.into(Service1Entity).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
170170
});
171171

172172
this.on("send00222", async (req) => {
173173
const { id } = req.data;
174174
const { Service1Entity } = this.entities;
175-
await INSERT.into(Service1Entity).entries(`ID =` + id); // UNSAFE: direct concatenation with `+`
175+
await INSERT.into(Service1Entity).entries({id: `ID =` + id}); // SAFE: `entries` call safely parses the property value
176176
});
177177

178178
this.on("send00223", async (req) => {
179179
const { id } = req.data;
180180
const { Service1Entity } = this.entities;
181-
await INSERT.into(Service1Entity).entries(`ID = ${id}`); // UNSAFE: direct interpolation in a template literal
182-
});
183-
184-
this.on("send00224", async (req) => {
185-
const { id } = req.data;
186-
const { Service1Entity } = this.entities;
187-
await INSERT.into(Service1Entity).entries`ID = ${id}`; // SAFE: tagged template expression
181+
await INSERT.into(Service1Entity).entries({id: `ID = ${id}`}); // SAFE: `entries` call safely parses the property value
188182
});
189183

190184
this.on("send00231", async (req) => {
@@ -214,19 +208,19 @@ module.exports = class Service1 extends cds.ApplicationService {
214208
this.on("send00241", async (req) => {
215209
const { id } = req.data;
216210
const { Service1Entity } = this.entities;
217-
await UPSERT.into(Service1Entity).entries({ id: "" + id }); // UNSAFE: direct concatenation with `+`
211+
await UPSERT.into(Service1Entity).entries({ id: "" + id }); // SAFE: `entries` call safely parses the property value
218212
});
219213

220214
this.on("send00242", async (req) => {
221215
const { id } = req.data;
222216
const { Service1Entity } = this.entities;
223-
await UPSERT.into(Service1Entity).entries({ id: `` + id }); // UNSAFE: direct concatenation with `+`
217+
await UPSERT.into(Service1Entity).entries({ id: `` + id }); // SAFE: `entries` call safely parses the property value
224218
});
225219

226220
this.on("send00243", async (req) => {
227221
const { id } = req.data;
228222
const { Service1Entity } = this.entities;
229-
await UPSERT.into(Service1Entity).entries({ id: `${id}` }); // UNSAFE: direct interpolation in a template literal
223+
await UPSERT.into(Service1Entity).entries({ id: `${id}` }); // SAFE: `entries` call safely parses the property value
230224
});
231225

232226
this.on("send00251", async (req) => {
@@ -267,7 +261,7 @@ module.exports = class Service1 extends cds.ApplicationService {
267261

268262
this.on("send33", async (req) => {
269263
const { id } = req.data;
270-
this.create(`Service1Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
264+
this.create(`Service1Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
271265
});
272266

273267
this.on("send34", async (req) => {
@@ -277,12 +271,12 @@ module.exports = class Service1 extends cds.ApplicationService {
277271

278272
this.on("send35", async (req) => {
279273
const { id } = req.data;
280-
this.insert(`Service1Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
274+
this.insert(`Service1Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
281275
});
282276

283277
this.on("send36", async (req) => {
284278
const { id } = req.data;
285-
this.upsert(`Service1Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
279+
this.upsert(`Service1Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
286280
});
287281

288282
this.on("send37", async (req) => {
@@ -307,7 +301,7 @@ module.exports = class Service1 extends cds.ApplicationService {
307301
this.on("send43", async (req) => {
308302
const { id } = req.data;
309303
const Service2 = await cds.connect.to("Service2");
310-
Service2.create(`Service2Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
304+
Service2.create(`Service2Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
311305
});
312306

313307
this.on("send44", async (req) => {
@@ -319,13 +313,13 @@ module.exports = class Service1 extends cds.ApplicationService {
319313
this.on("send45", async (req) => {
320314
const { id } = req.data;
321315
const Service2 = await cds.connect.to("Service2");
322-
Service2.insert(`Service2Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
316+
Service2.insert(`Service2Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
323317
});
324318

325319
this.on("send46", async (req) => {
326320
const { id } = req.data;
327321
const Service2 = await cds.connect.to("Service2");
328-
Service2.upsert(`Service2Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
322+
Service2.upsert(`Service2Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
329323
});
330324

331325
this.on("send47", async (req) => {
@@ -457,7 +451,7 @@ module.exports = class Service1 extends cds.ApplicationService {
457451
const { id } = req.data;
458452
const Service2 = await cds.connect.to("Service2");
459453
Service2.tx(async (tx) => {
460-
tx.create(`Service2Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
454+
tx.create(`Service2Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
461455
});
462456
});
463457

@@ -473,15 +467,15 @@ module.exports = class Service1 extends cds.ApplicationService {
473467
const { id } = req.data;
474468
const Service2 = await cds.connect.to("Service2");
475469
Service2.tx(async (tx) => {
476-
tx.insert(`Service2Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
470+
tx.insert(`Service2Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
477471
});
478472
});
479473

480474
this.on("send96", async (req) => {
481475
const { id } = req.data;
482476
const Service2 = await cds.connect.to("Service2");
483477
Service2.tx(async (tx) => {
484-
tx.upsert(`Service2Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
478+
tx.upsert(`Service2Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
485479
});
486480
});
487481

@@ -512,7 +506,7 @@ module.exports = class Service1 extends cds.ApplicationService {
512506
this.on("send103", async (req) => {
513507
const { id } = req.data;
514508
this.tx(async (tx) => {
515-
tx.create(`Service1Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
509+
tx.create(`Service1Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
516510
});
517511
});
518512

@@ -526,14 +520,14 @@ module.exports = class Service1 extends cds.ApplicationService {
526520
this.on("send105", async (req) => {
527521
const { id } = req.data;
528522
this.tx(async (tx) => {
529-
tx.insert(`Service1Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
523+
tx.insert(`Service1Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
530524
});
531525
});
532526

533527
this.on("send106", async (req) => {
534528
const { id } = req.data;
535529
this.tx(async (tx) => {
536-
tx.upsert(`Service1Entity`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
530+
tx.upsert(`Service1Entity`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
537531
});
538532
});
539533

@@ -563,7 +557,7 @@ module.exports = class Service1 extends cds.ApplicationService {
563557
this.on("send113", async (req) => {
564558
const { id } = req.data;
565559
cds.tx(async (tx) => {
566-
tx.create(`Entity1`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
560+
tx.create(`Entity1`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
567561
});
568562
});
569563

@@ -577,14 +571,14 @@ module.exports = class Service1 extends cds.ApplicationService {
577571
this.on("send115", async (req) => {
578572
const { id } = req.data;
579573
cds.tx(async (tx) => {
580-
tx.insert(`Entity1`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
574+
tx.insert(`Entity1`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
581575
});
582576
});
583577

584578
this.on("send116", async (req) => {
585579
const { id } = req.data;
586580
cds.tx(async (tx) => {
587-
tx.upsert(`Entity1`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
581+
tx.upsert(`Entity1`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
588582
});
589583
});
590584

@@ -614,7 +608,7 @@ module.exports = class Service1 extends cds.ApplicationService {
614608
this.on("send123", async (req) => {
615609
const { id } = req.data;
616610
cds.db.tx(async (tx) => {
617-
tx.create(`Entity1`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
611+
tx.create(`Entity1`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
618612
});
619613
});
620614

@@ -628,14 +622,14 @@ module.exports = class Service1 extends cds.ApplicationService {
628622
this.on("send125", async (req) => {
629623
const { id } = req.data;
630624
cds.db.tx(async (tx) => {
631-
tx.insert(`Entity1`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
625+
tx.insert(`Entity1`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
632626
});
633627
});
634628

635629
this.on("send126", async (req) => {
636630
const { id } = req.data;
637631
cds.db.tx(async (tx) => {
638-
tx.upsert(`Entity1`).entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
632+
tx.upsert(`Entity1`).entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
639633
});
640634
});
641635

@@ -693,17 +687,17 @@ module.exports = class Service1 extends cds.ApplicationService {
693687

694688
this.on("send001331", async (req) => {
695689
const { id } = req.data;
696-
cds.db.create("Entity1").entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
690+
cds.db.create("Entity1").entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
697691
});
698692

699693
this.on("send001332", async (req) => {
700694
const { id } = req.data;
701-
cds.db.create("Entity1").entries({id: `` + id}); // UNSAFE: direct concatenation with `+`
695+
cds.db.create("Entity1").entries({id: `` + id}); // SAFE: `entries` call safely parses the property value
702696
});
703697

704698
this.on("send001333", async (req) => {
705699
const { id } = req.data;
706-
cds.db.create("Entity1").entries({id: `${id}`}); // UNSAFE: direct interpolation in a template literal
700+
cds.db.create("Entity1").entries({id: `${id}`}); // SAFE: `entries` call safely parses the property value
707701
});
708702

709703
this.on("send001341", async (req) => {
@@ -728,32 +722,32 @@ module.exports = class Service1 extends cds.ApplicationService {
728722

729723
this.on("send001351", async (req) => {
730724
const { id } = req.data;
731-
cds.db.insert("Entity1").entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
725+
cds.db.insert("Entity1").entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
732726
});
733727

734728
this.on("send001352", async (req) => {
735729
const { id } = req.data;
736-
cds.db.insert("Entity1").entries({id: `` + id}); // UNSAFE: direct concatenation with `+`
730+
cds.db.insert("Entity1").entries({id: `` + id}); // SAFE: `entries` call safely parses the property value
737731
});
738732

739733
this.on("send001353", async (req) => {
740734
const { id } = req.data;
741-
cds.db.insert("Entity1").entries({id: `${id}`}); // UNSAFE: direct interpolation in a template literal
735+
cds.db.insert("Entity1").entries({id: `${id}`}); // SAFE: `entries` call safely parses the property value
742736
});
743737

744738
this.on("send001361", async (req) => {
745739
const { id } = req.data;
746-
cds.db.upsert("Entity1").entries({id: "" + id}); // UNSAFE: direct concatenation with `+`
740+
cds.db.upsert("Entity1").entries({id: "" + id}); // SAFE: `entries` call safely parses the property value
747741
});
748742

749743
this.on("send001362", async (req) => {
750744
const { id } = req.data;
751-
cds.db.upsert("Entity1").entries({id: `` + id}); // UNSAFE: direct concatenation with `+`
745+
cds.db.upsert("Entity1").entries({id: `` + id}); // SAFE: `entries` call safely parses the property value
752746
});
753747

754748
this.on("send001363", async (req) => {
755749
const { id } = req.data;
756-
cds.db.upsert("Entity1").entries({id: `${id}`}); // UNSAFE: direct interpolation in a template literal
750+
cds.db.upsert("Entity1").entries({id: `${id}`}); // SAFE: `entries` call safely parses the property value
757751
});
758752

759753
this.on("send001371", async (req) => {

0 commit comments

Comments
 (0)