Skip to content

Commit 9f6e342

Browse files
authored
fix: Server crashes on invalid Cloud Function or Cloud Job name; fixes security vulnerability [GHSA-6hh7-46r2-vf29](GHSA-6hh7-46r2-vf29) (#9024)
1 parent 901aaf8 commit 9f6e342

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

spec/ParseHooks.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,36 @@ describe('triggers', () => {
694694
expect(req.context).toBeUndefined();
695695
});
696696
});
697+
698+
describe('sanitizing names', () => {
699+
const invalidNames = [
700+
`test'%3bdeclare%20@q%20varchar(99)%3bset%20@q%3d'%5c%5cxxxxxxxxxxxxxxx.yyyyy'%2b'fy.com%5cxus'%3b%20exec%20master.dbo.xp_dirtree%20@q%3b--%20`,
701+
`test.function.name`,
702+
];
703+
704+
it('should not crash server and return error on invalid Cloud Function name', async () => {
705+
for (const invalidName of invalidNames) {
706+
let error;
707+
try {
708+
await Parse.Cloud.run(invalidName);
709+
} catch (err) {
710+
error = err;
711+
}
712+
expect(error).toBeDefined();
713+
expect(error.message).toMatch(/Invalid function/);
714+
}
715+
});
716+
717+
it('should not crash server and return error on invalid Cloud Job name', async () => {
718+
for (const invalidName of invalidNames) {
719+
let error;
720+
try {
721+
await Parse.Cloud.startJob(invalidName);
722+
} catch (err) {
723+
error = err;
724+
}
725+
expect(error).toBeDefined();
726+
expect(error.message).toMatch(/Invalid job/);
727+
}
728+
});
729+
});

src/triggers.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ const Category = {
8686
};
8787

8888
function getStore(category, name, applicationId) {
89+
const invalidNameRegex = /['"`]/;
90+
if (invalidNameRegex.test(name)) {
91+
// Prevent a malicious user from injecting properties into the store
92+
return {};
93+
}
94+
8995
const path = name.split('.');
9096
path.splice(-1); // remove last component
9197
applicationId = applicationId || Parse.applicationId;
@@ -94,7 +100,7 @@ function getStore(category, name, applicationId) {
94100
for (const component of path) {
95101
store = store[component];
96102
if (!store) {
97-
return undefined;
103+
return {};
98104
}
99105
}
100106
return store;

0 commit comments

Comments
 (0)