In the TNG episode the Pegasus, Starfleet Security was developing a cloaking device
To nitpick, "The Pegasus
" spoke of two separate branches, SF Security and SF Intelligence; it was the first episode to explicitly refer to this latter, supposedly more clandestine and underhanded sub-organization, a plot element the writer Ron D. Moore had long itched to introduce. It was SF Intel that was responsible for the development of the cloak against the UFP's interstellar legal commitments, while SF Security was only mentioned in passing, with SF Intel representative Admiral Pressman claiming that the Security branch boss was okay with what was going on. Considering what transpired, the claim was probably untrue or at least partially misleading.
SF Security does investigate. But rather than being "spooks", they are more like "cops" when doing this. Indeed, it appears that SF Security is the de facto only law enforcement force in the entire Federation, rather than just within Starfleet...