|
1 | 1 | const request = require('../lib/request'); |
2 | 2 | const Auth = require('../lib/Auth'); |
| 3 | +const Config = require('../lib/Config'); |
3 | 4 | const requestWithExpectedError = async params => { |
4 | 5 | try { |
5 | 6 | return await request(params); |
@@ -1613,4 +1614,92 @@ describe('Auth Adapter features', () => { |
1613 | 1614 | expect(authData.simpleAdapter && authData.simpleAdapter.id).toBe('simple1'); |
1614 | 1615 | expect(authData.codeBasedAdapter && authData.codeBasedAdapter.id).toBe('user1'); |
1615 | 1616 | }); |
| 1617 | + |
| 1618 | + describe('authData dot-notation injection and login crash', () => { |
| 1619 | + it('rejects dotted update key that targets authData sub-field', async () => { |
| 1620 | + const user = new Parse.User(); |
| 1621 | + user.setUsername('dotuser'); |
| 1622 | + user.setPassword('pass1234'); |
| 1623 | + await user.signUp(); |
| 1624 | + |
| 1625 | + const res = await request({ |
| 1626 | + method: 'PUT', |
| 1627 | + url: `http://localhost:8378/1/users/${user.id}`, |
| 1628 | + headers: { |
| 1629 | + 'Content-Type': 'application/json', |
| 1630 | + 'X-Parse-Application-Id': 'test', |
| 1631 | + 'X-Parse-REST-API-Key': 'rest', |
| 1632 | + 'X-Parse-Session-Token': user.getSessionToken(), |
| 1633 | + }, |
| 1634 | + body: JSON.stringify({ 'authData.anonymous".id': 'injected' }), |
| 1635 | + }).catch(e => e); |
| 1636 | + expect(res.status).toBe(400); |
| 1637 | + }); |
| 1638 | + |
| 1639 | + it('login does not crash when stored authData has unknown provider', async () => { |
| 1640 | + const user = new Parse.User(); |
| 1641 | + user.setUsername('dotuser2'); |
| 1642 | + user.setPassword('pass1234'); |
| 1643 | + await user.signUp(); |
| 1644 | + await Parse.User.logOut(); |
| 1645 | + |
| 1646 | + // Inject unknown provider directly in database to simulate corrupted data |
| 1647 | + const config = Config.get('test'); |
| 1648 | + await config.database.update( |
| 1649 | + '_User', |
| 1650 | + { objectId: user.id }, |
| 1651 | + { authData: { unknown_provider: { id: 'bad' } } } |
| 1652 | + ); |
| 1653 | + |
| 1654 | + // Login should not crash with 500 |
| 1655 | + const login = await request({ |
| 1656 | + method: 'GET', |
| 1657 | + url: `http://localhost:8378/1/login?username=dotuser2&password=pass1234`, |
| 1658 | + headers: { |
| 1659 | + 'X-Parse-Application-Id': 'test', |
| 1660 | + 'X-Parse-REST-API-Key': 'rest', |
| 1661 | + }, |
| 1662 | + }).catch(e => e); |
| 1663 | + expect(login.status).toBe(200); |
| 1664 | + expect(login.data.sessionToken).toBeDefined(); |
| 1665 | + }); |
| 1666 | + }); |
| 1667 | + |
| 1668 | + describe('challenge endpoint authData provider value validation', () => { |
| 1669 | + it('rejects challenge request with null provider value without 500', async () => { |
| 1670 | + const res = await request({ |
| 1671 | + method: 'POST', |
| 1672 | + url: 'http://localhost:8378/1/challenge', |
| 1673 | + headers: { |
| 1674 | + 'Content-Type': 'application/json', |
| 1675 | + 'X-Parse-Application-Id': 'test', |
| 1676 | + 'X-Parse-REST-API-Key': 'rest', |
| 1677 | + }, |
| 1678 | + body: JSON.stringify({ |
| 1679 | + authData: { anonymous: null }, |
| 1680 | + challengeData: { anonymous: { token: '123456' } }, |
| 1681 | + }), |
| 1682 | + }).catch(e => e); |
| 1683 | + expect(res.status).toBeGreaterThanOrEqual(400); |
| 1684 | + expect(res.status).toBeLessThan(500); |
| 1685 | + }); |
| 1686 | + |
| 1687 | + it('rejects challenge request with non-object provider value without 500', async () => { |
| 1688 | + const res = await request({ |
| 1689 | + method: 'POST', |
| 1690 | + url: 'http://localhost:8378/1/challenge', |
| 1691 | + headers: { |
| 1692 | + 'Content-Type': 'application/json', |
| 1693 | + 'X-Parse-Application-Id': 'test', |
| 1694 | + 'X-Parse-REST-API-Key': 'rest', |
| 1695 | + }, |
| 1696 | + body: JSON.stringify({ |
| 1697 | + authData: { anonymous: 'string_value' }, |
| 1698 | + challengeData: { anonymous: { token: '123456' } }, |
| 1699 | + }), |
| 1700 | + }).catch(e => e); |
| 1701 | + expect(res.status).toBeGreaterThanOrEqual(400); |
| 1702 | + expect(res.status).toBeLessThan(500); |
| 1703 | + }); |
| 1704 | + }); |
1616 | 1705 | }); |
0 commit comments