For context: my story is set in a world very much like Earth, just with low-level low-impact magic added (needed for the story idea and plot). But other than that extra, it can very well be 100% realistic Earth.
Is it Earth, or not Earth? This is a very important distinction.
Earth "but with magic"
So, Earth. (Note that the real modern Earth has magic: the majority of real people believe in some sort of magic.) The continents and countries are as they are. There's an Europe, there's an America, there's a Stackexchange. Maybe there's an Atlantis near Santorini and Tiktok is incorporated there.
In this case, your characters can openly make cultural references, just like you make cultural references. You can make any reference you want. If the world is different from the actual real Earth in subtle ways, you can even reflect this in references people make. Maybe Brazil defeated Germany 7:1, maybe Doge was a pitbull.
Not Earth
The world and its societies may resemble the modern world of 2025, with cars, digital watches, and the Internet, but it's not Earth. The continents are different, the history is different, and the culture is different. There's no The Sword of Welleran, no Quatermass and the Pit, no G.I. Samurai, which is to say, this world SUCKS.
Then you can still make references, but you have to be very careful about it, because the characters have no knowledge of Earth culture, they'll be kind of drawing eternal truths from the great unknown and seriously threatening good taste and the suspension of disbelief. It's great when you can pull it off, which you should try, because it's unavoidable that you will be making some sort of references. Almost everything is a reference, if you think about it.
Suppose you're writing a fantasy novel that's not set on Earth, in English. The characters in the novel are not speaking English, or at least you and the readers have come to an implicit understanding that this question won't be raised. So far, so good. But then:
- some words have an explicitly foreign origin. Is it ok to say "gambeson", knowing it's French, or should you go for a generic descriptive term ("armor padding"), or invent your own?
- some words reference real-world toponyms, how about those?
- what about Biblical references? Can you call a monster a "leviathan"? How about a "crusade"? What if it's a metaphor ("the city administration has gone on a crusade against littering"), does your world even have holy wars for anyone to use the metaphor?
- some books have English wordplay that's heavily dependent on the peculiarities of the English language -- this breaks the "don't ask about the language" agreement (and won't translate well to a real-world foreign language if/when you're publishing internationally).
Tthe answer is, all references are art, and how well they are received depends on the context and the audience. My native language is not big on biblical references, and they stick out like a sore thumb and break immersion. A crusade in English I'd probably let slide. Florentine fencing in a world with no Florence will make me see red.
One thing you absolutely should not do is steal glory. The reader has to perceive references as subtly ironic and poking at immersion; he should think you wanted him to get the reference without making the reference too explicit. There are two bad outcomes: one when the reader thinks the reference is too obviously crude and tasteless, and one when the reader gets the reference but thinks that you did not expect him to get it, that you stole a clever phrase from Alexander / Napoleon / Ted K / whoever to make your fictional character more impressive. In the space between these two extremes, references shine, but the stronger people feel about the subject being referenced, the narrower that space is.
Also, do not make major characters who are fictionalized versions of real people or characters borrowed wholesale from other works unless this is explicitly your whole schtick ("Sengoku in spaaaaaaaaaace!"), otherwise it's tasteless. The videogame Arcanum: of Steamworks and Magick Obscura has a major character named "Gilbert Bates" (with a minor rival, Cedric Appleby). For a throwaway gag, this would be tolerable, but Gilbert Bates turns out to be a big player in the epic drama of the game that has nothing to do with Microsoft or Bill Gates's political activism. However, a "640 kilobytes ought to be enough for anybody" line* would be perfect anywhere (with kilobytes replaced with a setting-appropriate resource).
* Bill Gates did not actually say exactly that line, but he did say he'd used to hold that opinion.
In-universe cultural references
You can make a character whose quirk is openly referencing in-universe works of art. A possible pitfall here is the in-universe works can themselves be references to the real world, and you have to be careful about them. Any culture can have a famous tragic love story, but one with a balcony scene and a double accidental poisoning may be too on the nose.