I went to replace a ceiling fan on a cathedral ceiling in my house yesterday, and upon removing the old fan I noticed that there is no electrical box where the fan was mounted. The fan was hung from a ceiling joist with romex running to the location, and the wiring was done underneath the fan's mounting bracket and canopy cover. It looks like the replacement fan would be wired in the same area, so does it matter if there's no electrical box under the drywall? If so, why?
Electrical boxes serve several functions. They protect wiring where insulation has been removed. They prevent inadvertent contact with exposed components. They contain sparks when the worst occurs. And they provide standard mounting points for fixtures.
I'd be inclined to "code things up" with a wraparound box like so:
Nonmetallic ceiling joist box for ceiling fans. 4'' diameter x 2 1/8'' deep, 12.0 cu. in. 4 clamps, 2 1/2'' knockouts. Maximum fixture weight is 150 lb., maximum fan weight is 70 lb. Exceeds National Electrical code requirements. Recommended for earthquake areas.
As far as code goes, the wiring must be done in a box and that box must be rated to support the weight of the fan. It's not code compliant if it were to be inspected.
But on to what this means to you, since most likely an inspector wouldn't check it.. You could say that the joist will support the fan and that the wires are secured, but if any were to come loose it could cause a fire since there isn't a box to protect it. That's about it.
I have this exact thing done under one of my ceiling fans in my new house and it seems to be a common issue. I've not gotten around to fixing it and it most likely won't ever cause a fire, but it would still be safer to pay a couple dollars and prevent it in any case.
I would not recommend remounting the fan the way it was installed.
There are inexpensive and easy to install remodel solutions that address this very easily. I'd recommend a box that hangs in-between the joists, such as:
Assuming your ceiling is just drywall, you can use a 4" to 4-3/8" hole saw to drill a hole between the joists, then snake the support bracket up through the hole, extend into place, then attach the electrical box to it. It is typically a pretty smooth process, and with a little patience, won't require you to get into the attic at all, nor roll around in fiberglass.
FWIW, I recently discovered the "grit-based" hole saws for cutting through plaster. I would strongly recommend these if you have plaster walls or ceilings - I learned this after ruining a couple hole saws cutting through 1.5" plaster recently.