Skip to content

Commit 7b93470

Browse files
Merge pull request #754 from contentstack/bugfix/audit-log
bug resolved
2 parents e558c1a + 50c9fee commit 7b93470

File tree

8 files changed

+525
-455
lines changed

8 files changed

+525
-455
lines changed

.talismanrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ fileignoreconfig:
8181
checksum: 1fec859f4d41e1acb5cdab8fdfba7c1978532a7f98f4fd26674153755f926d64
8282
- filename: ui/package-lock.json
8383
checksum: 4abcc89c75b7ddca8128fd72faafbb9b159f02611d96325bcd355283074ce287
84+
- filename: ui/src/components/ContentMapper/index.scss
85+
checksum: 46f8fde3b745feba40943f00d8d52714d0f320202c86b62f6c5ded73c2dbcf4c
86+
8487

8588
fileignoreconfig:
8689
- filename: api/src/services/migration.service.ts

api/src/services/migration.service.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import fsPromises from 'fs/promises';
3434
import { matchesSearchText } from '../utils/search.util.js';
3535
import { taxonomyService } from './taxonomy.service.js';
3636
import { globalFieldServie } from './globalField.service.js';
37-
// import { getSafePath } from "../utils/sanitize-path.utils.js";
37+
import { getSafePath } from '../utils/sanitize-path.utils.js';
3838

3939
/**
4040
* Creates a test stack.
@@ -727,7 +727,16 @@ const getAuditData = async (req: Request): Promise<any> => {
727727
}
728728
};
729729
if (entriesSelectFieldExists) {
730-
const fileContent = await fsPromises?.readFile(entriesSelectFieldPath, 'utf8');
730+
const safeEntriesSelectFieldPath = getSafePath(entriesSelectFieldPath);
731+
// Ensure the sanitized path is within the auditLogPath directory
732+
if (!safeEntriesSelectFieldPath.startsWith(auditLogPath)) {
733+
throw new BadRequestError('Access to this file is not allowed.');
734+
}
735+
// Additional path traversal prevention
736+
if (!safeEntriesSelectFieldPath.startsWith(auditLogPath) || safeEntriesSelectFieldPath.includes('..')) {
737+
throw new BadRequestError('Access to this file is not allowed.');
738+
}
739+
const fileContent = await fsPromises?.readFile(safeEntriesSelectFieldPath, 'utf8');
731740
try {
732741
if (typeof fileContent === 'string') {
733742
const parsed = JSON?.parse(fileContent);
@@ -739,7 +748,12 @@ const getAuditData = async (req: Request): Promise<any> => {
739748
}
740749
}
741750
if (entriesExists) {
742-
const fileContent = await fsPromises?.readFile(entriesPath, 'utf8');
751+
const safeEntriesPath = getSafePath(entriesPath);
752+
// Ensure the sanitized path is within the auditLogPath directory
753+
if (!safeEntriesPath.startsWith(auditLogPath)) {
754+
throw new BadRequestError('Access to this file is not allowed.');
755+
}
756+
const fileContent = await fsPromises?.readFile(safeEntriesPath, 'utf8');
743757
try {
744758
if (typeof fileContent === 'string') {
745759
const parsed = JSON?.parse(fileContent);
@@ -753,7 +767,19 @@ const getAuditData = async (req: Request): Promise<any> => {
753767
fileData = combinedData;
754768
} else {
755769
if (fs?.existsSync(filePath)) {
756-
const fileContent = await fsPromises?.readFile(filePath, 'utf8');
770+
const safeFilePath = getSafePath(filePath);
771+
// Ensure the sanitized path is within the auditLogPath directory
772+
if (!safeFilePath.startsWith(auditLogPath)) {
773+
throw new BadRequestError('Access to this file is not allowed.');
774+
}
775+
// Prevent path traversal by checking for '..' and ensuring the path is within auditLogPath
776+
if (
777+
safeFilePath.includes('..') ||
778+
!safeFilePath.startsWith(auditLogPath)
779+
) {
780+
throw new BadRequestError('Path traversal detected or access to this file is not allowed.');
781+
}
782+
const fileContent = await fsPromises?.readFile(safeFilePath, 'utf8');
757783
try {
758784
if (typeof fileContent === 'string') {
759785
fileData = JSON?.parse(fileContent);

ui/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,72 @@
11
.select-container {
2-
display: flex;
2+
display: flex;
33

4-
.select-wrapper {
5-
display: flex;
6-
margin-left: 1rem;
7-
}
4+
.select-wrapper {
5+
display: flex;
6+
margin-left: 1rem;
7+
}
88
}
99

1010
.Search-input-show {
11-
margin-bottom: 4px;
11+
margin-bottom: 4px;
1212
}
1313

14-
.PageLayout--primary .PageLayout__leftSidebar+.PageLayout__content .PageLayout__body {
15-
width: calc(100% - 15rem);
14+
.PageLayout--primary .PageLayout__leftSidebar + .PageLayout__content .PageLayout__body {
15+
width: calc(100% - 15rem);
1616
}
1717

1818
.Table__head__row {
19-
height: 100% !important;
19+
height: 100% !important;
2020
}
2121

2222
.PageLayout__body {
23-
.table-height {
24-
.Table {
25-
height: calc(100vh - 12.75rem) !important;
26-
}
27-
28-
.Table.TableWithPaginated {
29-
.Table__body {
30-
height: calc(100vh - 18.5rem) !important;
31-
}
32-
}
23+
.table-height {
24+
.Table {
25+
height: calc(100vh - 12.75rem) !important;
26+
}
27+
28+
.Table.TableWithPaginated {
29+
.Table__body {
30+
height: calc(100vh - 18.5rem) !important;
31+
}
3332
}
33+
}
3434
}
3535

3636
.custom-empty-state {
37-
.Icon--original {
38-
width: 207px !important;
39-
height: auto !important;
40-
max-width: 100%;
41-
display: block;
42-
margin: 0 auto;
43-
}
37+
.Icon--original {
38+
width: 207px !important;
39+
height: auto !important;
40+
max-width: 100%;
41+
display: block;
42+
margin: 0 auto;
43+
}
4444
}
4545

4646
.Table__head__column {
47-
align-items: center;
48-
display: flex;
49-
justify-content: space-between;
47+
align-items: center;
48+
display: flex;
49+
justify-content: space-between;
5050
}
5151

5252
.TablePagination {
53-
position: sticky;
54-
bottom: 0;
53+
position: sticky;
54+
bottom: 0;
5555
}
5656

5757
.tree-struct {
58-
width: 300px !important;
58+
width: 300px !important;
5959
}
6060

6161
.missing-val {
62-
width: 270px !important;
63-
}
62+
width: 270px !important;
63+
}
64+
65+
.tooltip-text {
66+
max-width: 220px;
67+
white-space: nowrap;
68+
overflow: hidden;
69+
text-overflow: ellipsis;
70+
display: inline-block;
71+
vertical-align: middle;
72+
}

0 commit comments

Comments
 (0)