When we think about important parts of a chimney the first things that come to mind are usually the bricks, the construction, and the mortar lined joints. These parts are all integral to the function of the chimney but there is another piece that is also very important and that piece is the flashing. Flashing lines the bottom edge of the chimney and, when it is installed and functioning properly, prevents water from entering the house via gaps between the roof and the edge of the chimney. This is typically done using two courses of flashing; The base and the counter. The base flashing is embedded in the shingles and bent upwards. The counter flashing is embedded in the mortar. Here are some photos of flashing that will fail or has already failed (leak:)
The corners need to be wrapped, or tight against opposing flashing. All chimney flashing needs to be properly caulked where required.

Bent flashing can permit water intrusion

Uncaulked flashing at the corners can permit water intrusion