שולחן ערוך, אורח חיים ר״כ

Shulchan Arukh, Orach Chayim 220

הטבת החלום ותעניתו. ובו ב סעיפים:
הרואה חלום ונפשו עגומה עליו יטיבנו באפי תלתא דרחימו ליה (פי' שאוהבים אותו) ולימא באפייהו חלמא טבא חזאי ולימרו אינהו טבא הוא וטבא להוי וכו':
Rectifying a dream and fasting about it. Contains two paragraphs.
When one has a dream and is anxious about it, one can rectify the dream in front of three people who care about him. He can say to them: "I had a good dream" and they can say to him "it is a good dream and it will be well."
יפה תענית לבטל חלום רע כאש לנעורת: הגה ודוקא בו ביום ואפי' בשבת וע' לקמן סי' רפ"ח:
It is good to fast to nullify a bad dream. Like fire on wood chips. Rem"a: Specifically, this applies to the same day and even on Shabbat.

Maginei Eretz: Shulchan Aruch Orach Chaim, Lemberg, 1893 (Public Domain) · Sefaria Community Translation (CC0) · 2 se'ifim