@7365admin1/core 3.48.1-staging.154 → 3.48.1-staging.155
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/.changeset/attendance-site-and-identity-scope.md +32 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +11 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/attendance-scope.e2e.test.mjs +420 -0
- package/test/e2e/harness.mjs +24 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Take the attendance caller's identity from the session, and scope every attendance
|
|
6
|
+
route to its estate.
|
|
7
|
+
|
|
8
|
+
Two separate defects, both on every route of `/api/attendances`.
|
|
9
|
+
|
|
10
|
+
**The caller's identity came from a cookie the caller writes.** Every handler read
|
|
11
|
+
`user` out of the raw `Cookie` header. That cookie is set by the browser itself
|
|
12
|
+
(`layer-common/composables/useLocalAuth.ts`, `setSession`) and by the mobile
|
|
13
|
+
clients from their own stored id; the server never compared it to the session.
|
|
14
|
+
`requireAuth` validates `sid` against Redis and puts the real caller on `req.user`
|
|
15
|
+
— which this controller ignored. A signed-in account could send
|
|
16
|
+
`Cookie: user=<somebody else>` and clock that person in, read their shift history
|
|
17
|
+
and check-in photo, or clock them out; and because check-out `$set`s `user` from
|
|
18
|
+
the request, checking somebody out also re-attributed their shift. The identity
|
|
19
|
+
now comes from `callerId(req)`, as the rest of the codebase resolves it.
|
|
20
|
+
|
|
21
|
+
**The estate was never checked.** All five routes now go through
|
|
22
|
+
`requireSiteReach`, the rule `/api/vehicles`, `/api/documents`,
|
|
23
|
+
`/api/service-providers` and `/api/incident-reports` already use. The four that
|
|
24
|
+
name a site in the URL check it before using it; `GET /id/:id` and
|
|
25
|
+
`PUT /id/:id/check-out` name only a record, so the site is read off the **stored**
|
|
26
|
+
row. The `customer.sites` branch matters here — the contracted agency whose staff
|
|
27
|
+
actually work these shifts holds no membership in the estate's organisation.
|
|
28
|
+
|
|
29
|
+
Every existing client already sends its own id in that cookie, so nothing
|
|
30
|
+
legitimate changes. A bare `Authorization: Bearer` call that sends no cookie at
|
|
31
|
+
all used to fail Joi's `user is required` with a 400 and now succeeds, which is
|
|
32
|
+
the only behaviour that gets looser rather than tighter.
|
package/dist/index.d.ts
CHANGED
|
@@ -4144,6 +4144,33 @@ declare function useAttendanceRepository(): {
|
|
|
4144
4144
|
deleteAttendance: (_id: string | ObjectId, session?: ClientSession) => Promise<number>;
|
|
4145
4145
|
};
|
|
4146
4146
|
|
|
4147
|
+
/**
|
|
4148
|
+
* Whose attendance this is, and which estate it was worked at.
|
|
4149
|
+
*
|
|
4150
|
+
* Two separate holes, both on every route of this mount.
|
|
4151
|
+
*
|
|
4152
|
+
* **1. The caller's identity came from a cookie the caller writes.** Every
|
|
4153
|
+
* handler here read `user` out of the raw `Cookie` header. That cookie is set by
|
|
4154
|
+
* the browser itself (`layer-common/composables/useLocalAuth.ts`, `setSession`)
|
|
4155
|
+
* and by the mobile clients from their own stored id; the server never checked
|
|
4156
|
+
* it against the session. `requireAuth` validates `sid` against Redis and puts
|
|
4157
|
+
* the real caller on `req.user` — which this controller ignored. So a signed-in
|
|
4158
|
+
* account could send `Cookie: user=<somebody else>` and check IN as them, read
|
|
4159
|
+
* THEIR shift history, or check them out. `checkOutAttendance` also `$set`s
|
|
4160
|
+
* `user` from the request, so checking somebody else out re-attributed their
|
|
4161
|
+
* shift to whoever asked.
|
|
4162
|
+
*
|
|
4163
|
+
* The identity now comes from `callerId(req)`, the session, exactly as the rest
|
|
4164
|
+
* of the codebase resolves it. Every honest client already sends its own id in
|
|
4165
|
+
* that cookie, so nothing legitimate changes.
|
|
4166
|
+
*
|
|
4167
|
+
* **2. The estate was never checked.** Four of the five name a site in the URL
|
|
4168
|
+
* and used it without asking; `GET /id/:id` and `PUT /id/:id/check-out` name only
|
|
4169
|
+
* a record, so the site is read off the STORED row. `requireSiteReach` is the
|
|
4170
|
+
* rule `/api/vehicles`, `/api/documents`, `/api/service-providers` and
|
|
4171
|
+
* `/api/incident-reports` already use, so the contracted agency whose staff
|
|
4172
|
+
* actually work these shifts reaches its own site through `customer.sites`.
|
|
4173
|
+
*/
|
|
4147
4174
|
declare function useAttendanceController(): {
|
|
4148
4175
|
checkInAttendance: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
4149
4176
|
getAllAttendances: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -40904,6 +40904,7 @@ function useAttendanceController() {
|
|
|
40904
40904
|
getAllAttendances: _getAllAttendances,
|
|
40905
40905
|
getAttendanceByUser: _getAttendanceByUser,
|
|
40906
40906
|
getAttendanceById: _getAttendanceById,
|
|
40907
|
+
getRawAttendanceById: _getRawAttendanceById,
|
|
40907
40908
|
deleteAttendance: _deleteAttendance
|
|
40908
40909
|
} = useAttendanceRepository();
|
|
40909
40910
|
const {
|
|
@@ -40911,11 +40912,7 @@ function useAttendanceController() {
|
|
|
40911
40912
|
checkOutAttendance: _checkOutAttendance
|
|
40912
40913
|
} = useAttendanceService();
|
|
40913
40914
|
async function checkInAttendance(req, res, next) {
|
|
40914
|
-
const
|
|
40915
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
40916
|
-
{}
|
|
40917
|
-
) : {};
|
|
40918
|
-
const user = cookies["user"] || "";
|
|
40915
|
+
const user = callerId(req);
|
|
40919
40916
|
const payload = { ...req.body, ...req.params, user };
|
|
40920
40917
|
const { error } = attendanceSchema.validate(payload);
|
|
40921
40918
|
if (error) {
|
|
@@ -40924,6 +40921,7 @@ function useAttendanceController() {
|
|
|
40924
40921
|
return;
|
|
40925
40922
|
}
|
|
40926
40923
|
try {
|
|
40924
|
+
await requireSiteReach(req, req.params.site);
|
|
40927
40925
|
const id = await _checkInAttendance(payload);
|
|
40928
40926
|
res.status(201).json({ message: "Attendance created successfully.", id });
|
|
40929
40927
|
return;
|
|
@@ -40958,6 +40956,7 @@ function useAttendanceController() {
|
|
|
40958
40956
|
const startDate = req.query.dateFrom ?? "";
|
|
40959
40957
|
const endDate = req.query.dateTo ?? "";
|
|
40960
40958
|
try {
|
|
40959
|
+
await requireSiteReach(req, site);
|
|
40961
40960
|
const data = await _getAllAttendances({
|
|
40962
40961
|
page,
|
|
40963
40962
|
limit,
|
|
@@ -40976,11 +40975,7 @@ function useAttendanceController() {
|
|
|
40976
40975
|
}
|
|
40977
40976
|
}
|
|
40978
40977
|
async function getAttendanceByUser(req, res, next) {
|
|
40979
|
-
const
|
|
40980
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
40981
|
-
{}
|
|
40982
|
-
) : {};
|
|
40983
|
-
const user = cookies["user"] || "";
|
|
40978
|
+
const user = callerId(req);
|
|
40984
40979
|
const query2 = { ...req.query, ...req.params, user };
|
|
40985
40980
|
const validation = import_joi62.default.object({
|
|
40986
40981
|
page: import_joi62.default.number().min(1).optional().allow("", null),
|
|
@@ -41006,6 +41001,7 @@ function useAttendanceController() {
|
|
|
41006
41001
|
const startDate = req.query.dateFrom ?? "";
|
|
41007
41002
|
const endDate = req.query.dateTo ?? "";
|
|
41008
41003
|
try {
|
|
41004
|
+
await requireSiteReach(req, site);
|
|
41009
41005
|
const data = await _getAttendanceByUser({
|
|
41010
41006
|
page,
|
|
41011
41007
|
limit,
|
|
@@ -41034,6 +41030,8 @@ function useAttendanceController() {
|
|
|
41034
41030
|
return;
|
|
41035
41031
|
}
|
|
41036
41032
|
try {
|
|
41033
|
+
const existing = await _getRawAttendanceById(_id);
|
|
41034
|
+
await requireSiteReach(req, existing?.site);
|
|
41037
41035
|
const data = await _getAttendanceById(_id);
|
|
41038
41036
|
res.json(data);
|
|
41039
41037
|
return;
|
|
@@ -41044,11 +41042,7 @@ function useAttendanceController() {
|
|
|
41044
41042
|
}
|
|
41045
41043
|
}
|
|
41046
41044
|
async function checkOutAttendance(req, res, next) {
|
|
41047
|
-
const
|
|
41048
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
41049
|
-
{}
|
|
41050
|
-
) : {};
|
|
41051
|
-
const user = cookies["user"] || "";
|
|
41045
|
+
const user = callerId(req);
|
|
41052
41046
|
const payload = { id: req.params.id, ...req.body, user };
|
|
41053
41047
|
const validation = import_joi62.default.object({
|
|
41054
41048
|
id: import_joi62.default.string().hex().required(),
|
|
@@ -41070,6 +41064,8 @@ function useAttendanceController() {
|
|
|
41070
41064
|
}
|
|
41071
41065
|
try {
|
|
41072
41066
|
const { id, ...value } = payload;
|
|
41067
|
+
const existing = await _getRawAttendanceById(id);
|
|
41068
|
+
await requireSiteReach(req, existing?.site);
|
|
41073
41069
|
await _checkOutAttendance(id, value);
|
|
41074
41070
|
res.json({ message: "Attendance updated successfully." });
|
|
41075
41071
|
return;
|