Do American Presidential primaries have to be democratic?

Or, perhaps a better question: Legally, how unfair can an American Presidential primary process be?

Is it possible, at this point, for a party to discard the primary system and go back to … well, smoking isn’t as common as it was, so let’s say ‘windowless rooms’ full of party bosses?

Is there any recourse if a candidate feels they’ve been unfairly barred from winning the primary due to vote rigging? In general, can a political party run a totally rigged primary by keeping people out of the voting locations and stuffing ballot boxes and so on?

(I suspect, based on my own knowledge and Wikipedia’s lack of mention of anything to the contrary, that, yeah, it’s pretty much entirely up to the party and that if the party bosses wanted to draw names from a hat or emulate Old Chicago (or Old New York and put a Tiger in their tank), it would be A-OK from a purely legal standpoint. Some verification would be nice, though.)

It depends on where. In some states, the primary process is established by law and parties (at least the major ones) are required to abide by it. In others, parties can nominate their candidates however they see fit, and the state will provide some resources for a primary election if they so choose.

In New York, the smattering of small parties that we have here generally do not hold primaries, but the Republicans and Democrats obviously do.

ETA: Actually, I should say that sometimes they hold primaries and sometimes they don’t; I’ve seen them do both.

At least some elements of fairness are required to be in play in primaries:

So long as political parties either use state assistance in running whatever sort of nominating process they use, and/or are organizations of public concern (the Republican nomination in Utah or the Democratic nomination in Hawaii being as tantamount-to-election now as the Democratic nomination in Texas was in 1944, after all), I imagine this precedent will continue to apply.