Skip to content

Commit 571b316

Browse files
committed
Create a new CQL injection test project and move the old one to a folder
1 parent dfa8c08 commit 571b316

File tree

10 files changed

+213
-0
lines changed

10 files changed

+213
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace advanced_security.log_injection.sample_entities;
2+
3+
entity Entity1 {
4+
Attribute1 : String(100);
5+
Attribute2 : String(100)
6+
}
7+
8+
entity Entity2 {
9+
Attribute3 : String(100);
10+
Attribute4 : String(100)
11+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@advanced-security/log-injection",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"@sap/cds": "^7",
6+
"express": "^4.17.1",
7+
"@cap-js/sqlite": "*"
8+
},
9+
"scripts": {
10+
"start": "cds-serve",
11+
"watch": "cds watch"
12+
},
13+
"cds": {
14+
"requires": {
15+
"service-1": {
16+
"impl": "srv/service1.js"
17+
},
18+
"service-2": {
19+
"impl": "srv/service2.js"
20+
}
21+
}
22+
}
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const cds = require("@sap/cds");
2+
const app = require("express")();
3+
4+
cds.serve("all").in(app);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using { advanced_security.log_injection.sample_entities as db_schema } from '../db/schema';
2+
3+
/* Uncomment the line below to make the service hidden */
4+
// @protocol: 'none'
5+
service Service1 @(path: '/service-1') {
6+
/* Entity to send READ/GET about. */
7+
entity Service1Entity as projection on db_schema.Entity1 excluding { Attribute2 }
8+
9+
/* API to talk to Service1. */
10+
action send1 (
11+
messageToPass : String
12+
) returns String;
13+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
const cds = require("@sap/cds");
2+
3+
module.exports = class Service1 extends cds.ApplicationService {
4+
init() {
5+
/* ========== Service1 running query on the database service using `cds.run` and friends using Fluent API ========== */
6+
this.on("send11", async (req) => {
7+
const { id } = req.data;
8+
const query = SELECT.from`Entity1`.where("ID=" + id);
9+
cds.run(query);
10+
});
11+
12+
this.on("send12", async (req) => {
13+
const { id } = req.data;
14+
cds.read("Entity1").where("ID =" + id);
15+
});
16+
17+
this.on("send13", async (req) => {
18+
const { id } = req.data;
19+
cds.create("Entity1").entries({id: "" + id});
20+
});
21+
22+
this.on("send14", async (req) => {
23+
const { id, amount } = req.data;
24+
cds.update("Entity1").set("col1 = col1" + amount).where("col1 = " + id);
25+
});
26+
27+
this.on("send15", async (req) => {
28+
const { id } = req.data;
29+
cds.upsert("Entity1").entries({id: "" + id});
30+
});
31+
32+
this.on("send16", async (req) => {
33+
const { id } = req.data;
34+
cds.delete("Entity1").where("ID =" + id);
35+
});
36+
37+
/* ========== Service1 running query on itself by `await`-ing the query ========== */
38+
this.on("send21", async (req) => {
39+
const { id } = req.data;
40+
const { Service1Entity } = this.entities;
41+
await SELECT.from(Service1Entity).where("ID=" + id);
42+
});
43+
44+
this.on("send22", async (req) => {
45+
const { id } = req.data;
46+
const { Service1Entity } = this.entities;
47+
await INSERT.into(Service1Entity).entries({ id: "" + id });
48+
});
49+
50+
this.on("send23", async (req) => {
51+
const { id, amount } = req.data;
52+
const { Service1Entity } = this.entities;
53+
await UPDATE.entity(Service1Entity).set(`col1 = col1 -` + amount).where("id=" + id);
54+
});
55+
56+
this.on("send24", async (req) => {
57+
const { id } = req.data;
58+
const { Service1Entity } = this.entities;
59+
await UPSERT.into(Service1Entity).entries({ id: "" + id });
60+
});
61+
62+
this.on("send25", async (req) => {
63+
const { id } = req.data;
64+
const { Service1Entity } = this.entities;
65+
await DELETE.from(Service1Entity).where("ID =" + id);
66+
});
67+
68+
/* ========== Service1 running query on itself using `this.run` and friends using Fluent API ========== */
69+
this.on("send31", async (req) => {
70+
const { id } = req.data;
71+
const query = SELECT.from`Service1Entity`.where("ID=" + id);
72+
this.run(query);
73+
});
74+
75+
this.on("send32", async (req) => {
76+
const { id } = req.data;
77+
this.read(`Service1Entity`).where("ID =" + id);
78+
});
79+
80+
this.on("send33", async (req) => {
81+
const { id } = req.data;
82+
this.create(`Service1Entity`).entries({id: "" + id});
83+
});
84+
85+
this.on("send34", async (req) => {
86+
const { id, amount } = req.data;
87+
this.update(`Service1Entity`).set("col1 = col1" + amount).where("col1 = " + id);
88+
});
89+
90+
this.on("send35", async (req) => {
91+
const { id } = req.data;
92+
this.upsert(`Service1Entity`).entries({id: "" + id});
93+
});
94+
95+
this.on("send36", async (req) => {
96+
const { id } = req.data;
97+
this.delete(`Service1Entity`).where("ID =" + id);
98+
});
99+
100+
/* ========== Service1 running query on Service2 using `Service2.run` and friends ========== */
101+
this.on("send41", async (req) => {
102+
const { id } = req.data;
103+
const { Service2 } = await cds.connect.to("Service2");
104+
const query = SELECT.from`Service1Entity`.where("ID=" + id);
105+
Service2.run(query);
106+
});
107+
108+
this.on("send42", async (req) => {
109+
const { id } = req.data;
110+
const { Service2 } = await cds.connect.to("Service2");
111+
Service2.read(`Service2Entity`).where("ID =" + id);
112+
});
113+
114+
this.on("send43", async (req) => {
115+
const { id } = req.data;
116+
const { Service2 } = await cds.connect.to("Service2");
117+
Service2.create(`Service2Entity`).entries({id: "" + id});
118+
});
119+
120+
this.on("send44", async (req) => {
121+
const { id, amount } = req.data;
122+
const { Service2 } = await cds.connect.to("Service2");
123+
Service2.update(`Service2Entity`).set("col1 = col1" + amount).where("col1 = " + id);
124+
});
125+
126+
this.on("send45", async (req) => {
127+
const { id } = req.data;
128+
const { Service2 } = await cds.connect.to("Service2");
129+
Service2.upsert(`Service2Entity`).entries({id: "" + id});
130+
});
131+
132+
this.on("send46", async (req) => {
133+
const { id } = req.data;
134+
const { Service2 } = await cds.connect.to("Service2");
135+
Service2.delete(`Service2Entity`).where("ID =" + id);
136+
});
137+
}
138+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using { advanced_security.log_injection.sample_entities as db_schema } from '../db/schema';
2+
3+
/* Uncomment the line below to make the service hidden */
4+
// @protocol: 'none'
5+
service Service2 @(path: '/service-2') {
6+
/* Entity to send READ/GET about. */
7+
entity Service2Entity as projection on db_schema.Entity2 excluding { Attribute4 }
8+
9+
/* API to talk to Service2. */
10+
action send2 (
11+
messageToPass: String
12+
) returns String;
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const cds = require("@sap/cds");
2+
3+
module.exports = cds.service.impl(function () {
4+
/* Log upon receiving an "send2" event. */
5+
this.on("send2", async (msg) => {
6+
const { messageToPass } = msg.data;
7+
/* Do something with the received data; customize below to individual needs. */
8+
const doSomething = console.log;
9+
doSomething(messageToPass);
10+
});
11+
});

0 commit comments

Comments
 (0)