Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bcryptjs": "3.0.3",
"commander": "14.0.3",
"cors": "2.8.6",
"deepcopy": "2.1.0",
"express": "5.2.1",
"express-rate-limit": "8.2.1",
"follow-redirects": "1.15.9",
Expand Down
114 changes: 108 additions & 6 deletions spec/vulnerabilities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,23 @@ describe('Vulnerabilities', () => {
});

it('denies __proto__ after a sibling nested object', async () => {
// Cannot test via HTTP because deepcopy() strips __proto__ before the denylist
// check runs. Test objectContainsKeyValue directly with a JSON.parse'd object
// that preserves __proto__ as an own property.
const Utils = require('../lib/Utils');
const data = JSON.parse('{"profile": {"name": "alice"}, "__proto__": {"isAdmin": true}}');
expect(Utils.objectContainsKeyValue(data, '__proto__', undefined)).toBe(true);
const headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
};
const response = await request({
headers,
method: 'POST',
url: 'http://localhost:8378/1/classes/PP',
body: JSON.stringify(
JSON.parse('{"profile": {"name": "alice"}, "__proto__": {"isAdmin": true}}')
),
}).catch(e => e);
expect(response.status).toBe(400);
const text = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
expect(text.code).toBe(Parse.Error.INVALID_KEY_NAME);
expect(text.error).toContain('__proto__');
});

it('denies constructor after a sibling nested object', async () => {
Expand Down Expand Up @@ -2644,4 +2655,95 @@ describe('(GHSA-c442-97qw-j6c6) SQL Injection via $regex query operator field na
expect(result.body.errors[0].message).toMatch(/exceeds maximum allowed/);
});
});

describe('(GHSA-9ccr-fpp6-78qf) Schema poisoning via __proto__ bypassing requestKeywordDenylist and addField CLP', () => {
const headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
};

it('rejects __proto__ in request body via HTTP', async () => {
const response = await request({
headers,
method: 'POST',
url: 'http://localhost:8378/1/classes/ProtoTest',
body: JSON.stringify(JSON.parse('{"name":"test","__proto__":{"injected":"value"}}')),
}).catch(e => e);
expect(response.status).toBe(400);
const text = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
expect(text.code).toBe(Parse.Error.INVALID_KEY_NAME);
expect(text.error).toContain('__proto__');
});

it('does not add fields to a locked schema via __proto__', async () => {
const schema = new Parse.Schema('LockedSchema');
schema.addString('name');
schema.setCLP({
find: { '*': true },
get: { '*': true },
create: { '*': true },
update: { '*': true },
delete: { '*': true },
addField: {},
});
await schema.save();

// Attempt to inject a field via __proto__
const response = await request({
headers,
method: 'POST',
url: 'http://localhost:8378/1/classes/LockedSchema',
body: JSON.stringify(JSON.parse('{"name":"test","__proto__":{"newField":"bypassed"}}')),
}).catch(e => e);

// Should be rejected by denylist
expect(response.status).toBe(400);

// Verify schema was not modified
const schemaResponse = await request({
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test',
},
method: 'GET',
url: 'http://localhost:8378/1/schemas/LockedSchema',
});
const fields = schemaResponse.data.fields;
expect(fields.newField).toBeUndefined();
});

it('does not cause schema type conflict via __proto__', async () => {
const schema = new Parse.Schema('TypeConflict');
schema.addString('name');
schema.addString('score');
schema.setCLP({
find: { '*': true },
get: { '*': true },
create: { '*': true },
update: { '*': true },
delete: { '*': true },
addField: {},
});
await schema.save();

// Attempt to inject 'score' as Number via __proto__
const response = await request({
headers,
method: 'POST',
url: 'http://localhost:8378/1/classes/TypeConflict',
body: JSON.stringify(JSON.parse('{"name":"test","__proto__":{"score":42}}')),
}).catch(e => e);

// Should be rejected by denylist
expect(response.status).toBe(400);

// Verify 'score' field is still String type
const obj = new Parse.Object('TypeConflict');
obj.set('name', 'valid');
obj.set('score', 'string-value');
await obj.save();
expect(obj.get('score')).toBe('string-value');
});
});
});
4 changes: 1 addition & 3 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { Parse } from 'parse/node';
import _ from 'lodash';
// @flow-disable-next
import intersect from 'intersect';
// @flow-disable-next
import deepcopy from 'deepcopy';
import logger from '../logger';
import Utils from '../Utils';
import * as SchemaController from './SchemaController';
Expand Down Expand Up @@ -541,7 +539,7 @@ class DatabaseController {
const originalQuery = query;
const originalUpdate = update;
// Make a copy of the object, so we don't mutate the incoming data.
update = deepcopy(update);
update = structuredClone(update);
var relationUpdates = [];
var isMaster = acl === undefined;
var aclGroup = acl || [];
Expand Down
4 changes: 1 addition & 3 deletions src/Controllers/SchemaController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import SchemaCache from '../Adapters/Cache/SchemaCache';
import DatabaseController from './DatabaseController';
import Config from '../Config';
import { createSanitizedError } from '../Error';
// @flow-disable-next
import deepcopy from 'deepcopy';
import type {
Schema,
SchemaFields,
Expand Down Expand Up @@ -573,7 +571,7 @@ class SchemaData {
if (!this.__data[schema.className]) {
const data = {};
data.fields = injectDefaultSchema(schema).fields;
data.classLevelPermissions = deepcopy(schema.classLevelPermissions);
data.classLevelPermissions = structuredClone(schema.classLevelPermissions);
data.indexes = schema.indexes;

const classProtectedFields = this.__protectedFields[schema.className];
Expand Down
5 changes: 3 additions & 2 deletions src/GraphQL/loaders/functionsMutations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLNonNull, GraphQLEnumType } from 'graphql';
import deepcopy from 'deepcopy';

import { mutationWithClientMutationId } from 'graphql-relay';
import { cloneArgs } from '../parseGraphQLUtils';
import { FunctionsRouter } from '../../Routers/FunctionsRouter';
import * as defaultGraphQLTypes from './defaultGraphQLTypes';

Expand Down Expand Up @@ -44,7 +45,7 @@ const load = parseGraphQLSchema => {
},
mutateAndGetPayload: async (args, context) => {
try {
const { functionName, params } = deepcopy(args);
const { functionName, params } = cloneArgs(args);
const { config, auth, info } = context;

return {
Expand Down
10 changes: 5 additions & 5 deletions src/GraphQL/loaders/parseClassMutations.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GraphQLNonNull } from 'graphql';
import { fromGlobalId, mutationWithClientMutationId } from 'graphql-relay';
import getFieldNames from 'graphql-list-fields';
import deepcopy from 'deepcopy';

import * as defaultGraphQLTypes from './defaultGraphQLTypes';
import { extractKeysAndInclude, getParseClassMutationConfig } from '../parseGraphQLUtils';
import { extractKeysAndInclude, getParseClassMutationConfig, cloneArgs } from '../parseGraphQLUtils';
import * as objectsMutations from '../helpers/objectsMutations';
import * as objectsQueries from '../helpers/objectsQueries';
import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLController';
Expand Down Expand Up @@ -75,7 +75,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
},
mutateAndGetPayload: async (args, context, mutationInfo) => {
try {
let { fields } = deepcopy(args);
let { fields } = cloneArgs(args);
if (!fields) { fields = {}; }
const { config, auth, info } = context;

Expand Down Expand Up @@ -178,7 +178,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
},
mutateAndGetPayload: async (args, context, mutationInfo) => {
try {
let { id, fields } = deepcopy(args);
let { id, fields } = cloneArgs(args);
if (!fields) { fields = {}; }
const { config, auth, info } = context;

Expand Down Expand Up @@ -284,7 +284,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
},
mutateAndGetPayload: async (args, context, mutationInfo) => {
try {
let { id } = deepcopy(args);
let { id } = cloneArgs(args);
const { config, auth, info } = context;

const globalIdObject = fromGlobalId(id);
Expand Down
8 changes: 4 additions & 4 deletions src/GraphQL/loaders/parseClassQueries.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { GraphQLNonNull } from 'graphql';
import { fromGlobalId } from 'graphql-relay';
import getFieldNames from 'graphql-list-fields';
import deepcopy from 'deepcopy';

import pluralize from 'pluralize';
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
import * as objectsQueries from '../helpers/objectsQueries';
import { ParseGraphQLClassConfig } from '../../Controllers/ParseGraphQLController';
import { transformClassNameToGraphQL } from '../transformers/className';
import { extractKeysAndInclude } from '../parseGraphQLUtils';
import { extractKeysAndInclude, cloneArgs } from '../parseGraphQLUtils';

const getParseClassQueryConfig = function (parseClassConfig: ?ParseGraphQLClassConfig) {
return (parseClassConfig && parseClassConfig.query) || {};
Expand Down Expand Up @@ -75,7 +75,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
return await getQuery(
parseClass,
_source,
deepcopy(args),
cloneArgs(args),
context,
queryInfo,
parseGraphQLSchema.parseClasses
Expand All @@ -99,7 +99,7 @@ const load = function (parseGraphQLSchema, parseClass, parseClassConfig: ?ParseG
async resolve(_source, args, context, queryInfo) {
try {
// Deep copy args to avoid internal re assign issue
const { where, order, skip, first, after, last, before, options } = deepcopy(args);
const { where, order, skip, first, after, last, before, options } = cloneArgs(args);
const { readPreference, includeReadPreference, subqueryReadPreference } = options || {};
const { config, auth, info } = context;
const selectedFields = getFieldNames(queryInfo);
Expand Down
10 changes: 5 additions & 5 deletions src/GraphQL/loaders/schemaMutations.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Parse from 'parse/node';
import { GraphQLNonNull } from 'graphql';
import deepcopy from 'deepcopy';

import { mutationWithClientMutationId } from 'graphql-relay';
import * as schemaTypes from './schemaTypes';
import { transformToParse, transformToGraphQL } from '../transformers/schemaFields';
import { enforceMasterKeyAccess } from '../parseGraphQLUtils';
import { enforceMasterKeyAccess, cloneArgs } from '../parseGraphQLUtils';
import { getClass } from './schemaQueries';
import { createSanitizedError } from '../../Error';

Expand All @@ -28,7 +28,7 @@ const load = parseGraphQLSchema => {
},
mutateAndGetPayload: async (args, context) => {
try {
const { name, schemaFields } = deepcopy(args);
const { name, schemaFields } = cloneArgs(args);
const { config, auth } = context;

enforceMasterKeyAccess(auth, config);
Expand Down Expand Up @@ -78,7 +78,7 @@ const load = parseGraphQLSchema => {
},
mutateAndGetPayload: async (args, context) => {
try {
const { name, schemaFields } = deepcopy(args);
const { name, schemaFields } = cloneArgs(args);
const { config, auth } = context;

enforceMasterKeyAccess(auth, config);
Expand Down Expand Up @@ -130,7 +130,7 @@ const load = parseGraphQLSchema => {
},
mutateAndGetPayload: async (args, context) => {
try {
const { name } = deepcopy(args);
const { name } = cloneArgs(args);
const { config, auth } = context;

enforceMasterKeyAccess(auth, config);
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQL/loaders/schemaQueries.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Parse from 'parse/node';
import deepcopy from 'deepcopy';

import { GraphQLNonNull, GraphQLList } from 'graphql';
import { transformToGraphQL } from '../transformers/schemaFields';
import * as schemaTypes from './schemaTypes';
import { enforceMasterKeyAccess } from '../parseGraphQLUtils';
import { enforceMasterKeyAccess, cloneArgs } from '../parseGraphQLUtils';

const getClass = async (name, schema) => {
try {
Expand All @@ -28,7 +28,7 @@ const load = parseGraphQLSchema => {
type: new GraphQLNonNull(schemaTypes.CLASS),
resolve: async (_source, args, context) => {
try {
const { name } = deepcopy(args);
const { name } = cloneArgs(args);
const { config, auth } = context;

enforceMasterKeyAccess(auth, config);
Expand Down
Loading
Loading