One should be more careful than usual when fasting but it is unlikely to invalidate the fast.
أَبَا هُرَيْرَةَ، عَنِ النَّبِيِّ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ أَنَّهُ قَالَ: «مَنْ تَوَضَّأَ فَلْيَسْتَنْثِرْ، وَمَنِ اسْتَجْمَرَ فَلْيُوتِرْ»
Abu Hurairah narrated that the Prophet ﷺ said, ‘Whoever performs Wudu should rinse his nose, and whoever cleanses himself (Istinjaa) should use an odd number (off stones).’ (Sahih al-Bukhari, 161).
This is one of many Hadith narrations encouraging Istinjaa, and this ruling will not change when one is fasting.
Water would have to go quite far to invalidate the fast. Hanafi scholars have mentioned it would have to go as far as an enema syringe which is unlikely. One should take reasonable caution but not fall prey to Waswasah. So one should not exaggerate Istinjaa when fasting and should also dry oneself before getting up, this will safeguard a person from invalidating the fast.
وَلَوْ بَالَغَ فِي الِاسْتِنْجَاءِ حَتَّى بَلَغَ مَوْضِعَ الْحُقْنَةِ فَسَدَ وَهَذَا قَلَّمَا يَكُونُ
أَيْ قَدْرُ مَا يَصِلُ إلَيْهِ رَأْسُ الْمِحْقَنَةِ الَّتِي هِيَ آلَةُ الِاحْتِقَانِ (رد المحتار على الدر المختار)
(Imam al-Haskafi): And if he exaggerates during Istinjaa such that it (water) reaches the place of the enema then it (the fast) is invalid, but this rarely happens.
(Imam Ibn Abideen): meaning (he exaggerates) to the extent that it (water) reaches the place where the head of an enema syringe, which is the tool used in an enema, would reach. (Radd al-Muhtaar).
Some people may have to be more cautious than the average person if they suffer from sever haemorrhoids which cause part of the colon to exit and re-enter, they should dry this before it re-enters.
وَفِي الْفَتْحِ خَرَجَ سُرْمُهُ فَغَسَلَهُ فَإِنْ قَامَ قَبْلَ أَنْ يُنَشِّفَهُ فَسَدَ صَوْمُهُ وَإِلَّا فَلَا
And in Fath (al-Qadeer) he said, if a part of his colon exits and he washes it, then if he stands before drying it, then his fast will be nullified, otherwise it will not. (Imam Ibn Abideen, Radd al-Muhtaar).
And Allah (Most High) Knows Best.
– Answered by Shaykh Noorud-deen (29.04.2021)
See also (video):