-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Allow read and write of internal fields with maintenanceKey
#8212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
4bd135c
fix: prevent stripping of user fields with masterKey
dblythy 906072d
feat: allow read and write of internal fields with masterKey
dblythy 7e9bb67
Update ParseUser.spec.js
dblythy 1be7ff5
fix lint
dblythy 62c14eb
run prettier
dblythy 5797d43
add maintenance
dblythy 7fc8227
Update UsersRouter.js
dblythy 9473747
Merge branch 'alpha' into fix-master
dblythy d06ae11
fix tests
dblythy 7538dec
Merge branch 'fix-master' of https://github.com/dblythy/parse-server …
dblythy bf8c511
Merge branch 'alpha' into fix-master
dblythy 3f14373
run lint
dblythy 4b88000
Merge branch 'fix-master' of https://github.com/dblythy/parse-server …
dblythy da1f421
Update UserController.js
dblythy f2bcdcc
fix tests
dblythy 9388f6a
Merge branch 'alpha' into fix-master
dblythy 62f511d
Merge branch 'alpha' into fix-master
dblythy 767e3a8
add ::1
dblythy d2c9e81
prettier
dblythy 518dec0
Update package-lock.json
dblythy 4814cce
Merge branch 'alpha' into fix-master
mtrezza 2e39b18
Merge branch 'alpha' into fix-master
dblythy 4dc463c
wip
dblythy e6ef840
Merge branch 'alpha' into fix-master
dblythy dabd501
prettier
dblythy 179879d
add access scopes to README
mtrezza 80ce4ed
Merge branch 'alpha' into fix-master
mtrezza cae5680
Merge branch 'alpha' into fix-master
dblythy 1987968
Update Middlewares.spec.js
dblythy 012c1ad
Merge branch 'fix-master' of https://github.com/dblythy/parse-server …
dblythy 57abc1f
Update ParseUser.spec.js
dblythy 82bf8a9
Update src/Options/index.js
dblythy c57efb1
Update src/Options/index.js
dblythy 687893b
docs
dblythy 5fce261
Update Middlewares.spec.js
dblythy 4e24693
Update ParseUser.spec.js
dblythy 60fd5d6
Merge branch 'alpha' into fix-master
dblythy 746c978
use example domain
mtrezza 1f199fe
Merge branch 'alpha' into fix-master
mtrezza 43f1d0e
Merge branch 'alpha' into fix-master
mtrezza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3522,40 +3522,128 @@ describe('Parse.User testing', () => { | |
}); | ||
}); | ||
|
||
it('should not allow updates to hidden fields', done => { | ||
it('should not allow updates to hidden fields', async () => { | ||
const emailAdapter = { | ||
sendVerificationEmail: () => {}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => Promise.resolve(), | ||
}; | ||
|
||
const user = new Parse.User(); | ||
user.set({ | ||
username: 'hello', | ||
password: 'world', | ||
email: '[email protected]', | ||
}); | ||
await reconfigureServer({ | ||
appName: 'unused', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
publicServerURL: 'http://localhost:8378/1', | ||
}); | ||
await user.signUp(); | ||
user.set('_email_verify_token', 'bad', { ignoreValidation: true }); | ||
await expectAsync(user.save()).toBeRejectedWith( | ||
new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid field name: _email_verify_token.') | ||
); | ||
}); | ||
|
||
reconfigureServer({ | ||
it('should allow updates to fields with maintenanceKey', async () => { | ||
const emailAdapter = { | ||
sendVerificationEmail: () => {}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => Promise.resolve(), | ||
}; | ||
const user = new Parse.User(); | ||
user.set({ | ||
username: 'hello', | ||
password: 'world', | ||
email: '[email protected]', | ||
}); | ||
await reconfigureServer({ | ||
appName: 'unused', | ||
maintenanceKey: 'test2', | ||
mtrezza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
verifyUserEmails: true, | ||
emailVerifyTokenValidityDuration: 5, | ||
accountLockout: { | ||
duration: 1, | ||
threshold: 1, | ||
}, | ||
emailAdapter: emailAdapter, | ||
publicServerURL: 'http://localhost:8378/1', | ||
}) | ||
.then(() => { | ||
return user.signUp(); | ||
}) | ||
.then(() => { | ||
return Parse.User.current().set('_email_verify_token', 'bad').save(); | ||
}) | ||
.then(() => { | ||
fail('Should not be able to update email verification token'); | ||
done(); | ||
}) | ||
.catch(err => { | ||
expect(err).toBeDefined(); | ||
done(); | ||
}); | ||
}); | ||
await user.signUp(); | ||
for (let i = 0; i < 2; i++) { | ||
try { | ||
await Parse.User.logIn(user.getEmail(), 'abc'); | ||
} catch (e) { | ||
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND); | ||
expect( | ||
e.message === 'Invalid username/password.' || | ||
e.message === | ||
'Your account is locked due to multiple failed login attempts. Please try again after 1 minute(s)' | ||
).toBeTrue(); | ||
} | ||
} | ||
await Parse.User.requestPasswordReset(user.getEmail()); | ||
const headers = { | ||
'X-Parse-Application-Id': 'test', | ||
'X-Parse-Rest-API-Key': 'rest', | ||
'X-Parse-Maintenance-Key': 'test2', | ||
'Content-Type': 'application/json', | ||
}; | ||
const userMaster = await request({ | ||
method: 'GET', | ||
url: `http://localhost:8378/1/classes/_User`, | ||
json: true, | ||
headers, | ||
}).then(res => res.data.results[0]); | ||
expect(Object.keys(userMaster).sort()).toEqual( | ||
[ | ||
'ACL', | ||
'_account_lockout_expires_at', | ||
'_email_verify_token', | ||
'_email_verify_token_expires_at', | ||
'_failed_login_count', | ||
'_perishable_token', | ||
'createdAt', | ||
'email', | ||
'emailVerified', | ||
'objectId', | ||
'updatedAt', | ||
'username', | ||
].sort() | ||
); | ||
const toSet = { | ||
_account_lockout_expires_at: new Date(), | ||
_email_verify_token: 'abc', | ||
_email_verify_token_expires_at: new Date(), | ||
_failed_login_count: 0, | ||
_perishable_token_expires_at: new Date(), | ||
_perishable_token: 'abc', | ||
}; | ||
await request({ | ||
method: 'PUT', | ||
headers, | ||
url: Parse.serverURL + '/users/' + userMaster.objectId, | ||
json: true, | ||
body: toSet, | ||
}).then(res => res.data); | ||
const update = await request({ | ||
method: 'GET', | ||
url: `http://localhost:8378/1/classes/_User`, | ||
json: true, | ||
headers, | ||
}).then(res => res.data.results[0]); | ||
for (const key in toSet) { | ||
const value = toSet[key]; | ||
if (update[key] && update[key].iso) { | ||
expect(update[key].iso).toEqual(value.toISOString()); | ||
} else if (value.toISOString) { | ||
expect(update[key]).toEqual(value.toISOString()); | ||
} else { | ||
expect(update[key]).toEqual(value); | ||
} | ||
} | ||
}); | ||
|
||
it('should revoke sessions when setting paswword with masterKey (#3289)', done => { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ const publicServerURL = 'http://localhost:8378/1'; | |
describe('Regex Vulnerabilities', function () { | ||
beforeEach(async function () { | ||
await reconfigureServer({ | ||
maintenanceKey: 'test2', | ||
verifyUserEmails: true, | ||
emailAdapter, | ||
appName, | ||
|
@@ -98,11 +99,20 @@ describe('Regex Vulnerabilities', function () { | |
|
||
it('should work with plain token', async function () { | ||
expect(this.user.get('emailVerified')).toEqual(false); | ||
const current = await request({ | ||
method: 'GET', | ||
url: `http://localhost:8378/1/classes/_User/${this.user.id}`, | ||
json: true, | ||
headers: { | ||
'X-Parse-Application-Id': 'test', | ||
'X-Parse-Rest-API-Key': 'test', | ||
'X-Parse-Maintenance-Key': 'test2', | ||
'Content-Type': 'application/json', | ||
}, | ||
}).then(res => res.data); | ||
// It should work | ||
await request({ | ||
url: `${serverURL}/apps/test/[email protected]&token=${this.user.get( | ||
'_email_verify_token' | ||
)}`, | ||
url: `${serverURL}/apps/test/[email protected]&token=${current._email_verify_token}`, | ||
method: 'GET', | ||
}); | ||
await this.user.fetch({ useMasterKey: true }); | ||
|
@@ -164,8 +174,18 @@ describe('Regex Vulnerabilities', function () { | |
email: '[email protected]', | ||
}), | ||
}); | ||
await this.user.fetch({ useMasterKey: true }); | ||
const token = this.user.get('_perishable_token'); | ||
const current = await request({ | ||
method: 'GET', | ||
url: `http://localhost:8378/1/classes/_User/${this.user.id}`, | ||
json: true, | ||
headers: { | ||
'X-Parse-Application-Id': 'test', | ||
'X-Parse-Rest-API-Key': 'test', | ||
'X-Parse-Maintenance-Key': 'test2', | ||
'Content-Type': 'application/json', | ||
}, | ||
}).then(res => res.data); | ||
const token = current._perishable_token; | ||
const passwordResetResponse = await request({ | ||
url: `${serverURL}/apps/test/[email protected]&token=${token}`, | ||
method: 'GET', | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.