Commit d5faea1
committed
fix(sync): bound entry key size to prevent replica memory/disk exhaustion
Sync-peer-supplied entries were accepted with arbitrarily large keys,
bounded only by the codec's MAX_MESSAGE_SIZE (1 GiB). `validate_entry`
did not check key length, so a peer that opened a sync session could
push entries with huge keys and force every replica that synced them
to persist them — a peer-controllable memory and disk amplifier.
Note: the key-size check has to live in `validate_entry` (or an
equivalent post-deserialization hook), not in `RecordIdentifier::new`,
because `RecordIdentifier` derives `Deserialize` and peer-supplied
entries reach the replica via serde, bypassing the constructor
entirely.
Fix: add `MAX_ENTRY_KEY_SIZE = 4096` and reject any entry whose key
exceeds it with a new `ValidationFailure::KeyTooLarge { actual, max }`.
The check runs before signature verification so oversized entries are
rejected without spending crypto work. 4 KiB is deliberately generous
for legitimate use cases (keys are short identifiers / paths); tunable
if upstream prefers a different limit.
Reproduction: the added `test_peer_entry_with_oversized_key_rejected`
test builds a 1 MiB key into a `SignedEntry` and feeds it through
`insert_remote_entry`. Before the bound the test's predecessor
(`test_peer_entry_with_oversized_key_accepted`, run against upstream)
confirmed the entry was accepted. With the bound in place the test
asserts `KeyTooLarge` is returned, and that a key at exactly
`MAX_ENTRY_KEY_SIZE` is still accepted.1 parent 722c200 commit d5faea1
1 file changed
Lines changed: 82 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
606 | 615 | | |
607 | 616 | | |
608 | 617 | | |
| 618 | + | |
609 | 619 | | |
610 | 620 | | |
611 | 621 | | |
| |||
617 | 627 | | |
618 | 628 | | |
619 | 629 | | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
620 | 639 | | |
621 | 640 | | |
622 | 641 | | |
| |||
673 | 692 | | |
674 | 693 | | |
675 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
676 | 703 | | |
677 | 704 | | |
678 | 705 | | |
| |||
1781 | 1808 | | |
1782 | 1809 | | |
1783 | 1810 | | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
1784 | 1866 | | |
1785 | 1867 | | |
1786 | 1868 | | |
| |||
0 commit comments