Security at the city’s homeless shelters is so shoddy that one Harlem facility had its own in-house heroin dealer, according to records and fed-up workers.

Parkview Inn resident Alice Cuesta, 52, was finally busted last month with 60 glassines of heroin after clumsily dropping them right in front of an NYPD sergeant inside the elevator at the West 110th Street shelter, prosecutors said court papers.

Before her fateful fumble, Cuesta had held free rein at the shelter “for a long time,” law-enforcement and DHS sources told The Post — adding that the situation is similar at shelters across the city.

Security gaps, as well as overworked DHS officers who simply don’t have the time, training or help to conduct thorough investigations, have left some residents wondering if they wouldn’t be better off taking their chances on the street.

And that prospect has become even more terrifying since last week, when four homeless men were murdered by a crazed vagrant in Chinatown and a 6-year-old boy was viciously attacked by a street bum in Queens.

“I do not feel safe here. At all. It’s horrible,” said one female Parkview resident, 66, declining to give her name for fear of reprisal within the shelter.

“This is why people prefer to live on the streets,” she said of the safety issues at the shelter.

Another female Parkview resident, a 26-year-old domestic violence survivor, said, “There needs to be some kind of control here because it’s unsafe for all of us.

“And it’s never safe outside, so what could we do?”

Internal data obtained by The Post shows 95 residents — nearly half of the 192 clients at the Parkview — were considered “at risk” of being a danger either to others or themselves, as of the end of September.

The group included 25 clients listed as mentally ill, 20 parolees, four identified as sex offenders, two who had recently been arrested and one who had recently gotten out of prison, the internal data shows.

Even though all residents pass through a metal detector and have their bags screened upon entry, “heroin doesn’t ring in the metal detector,” noted a source, one of more than one-dozen DHS police officers who spoke with The Post on condition of anonymity about the challenges they face.

Knowing this, contraband-carrying clients often stuff smuggled goods in their underwear, bras and socks to avoid detection, sources said — and there’s almost nothing that can be done about it.

“We would have to see a bulge that clearly looks like a gun, knife or something very illegal to do something about it,” a DHS cop said.

If residents are flagged as having something suspicious on them that doesn’t appear to be a deadly weapon, they are allowed to simply walk back outside, ditch the contraband and re-enter, another DHS cop said.

Meanwhile, shelter staffers are only allowed to conduct “plain sight inspections” of clients’ quarters — meaning unless contraband is sitting out in the open, they can’t go rooting around without a warrant.

“If it’s not open, you can’t open it, unless it’s a facility refrigerator,” one source said. “[Officers] can’t just go in there and open drawers.”

Even if contraband is found during an inspection, an arrest can only be made if there is someone in the room at the time of the search and a DHS cop is present, sources said.

Contraband discovered at city shelters has ranged from drugs, guns and hoards of ammo to brass knuckles and even a long knife hidden in a cane, according to photos obtained by The Post.

Shelter staff can sanction or suspend a client for having contraband, cutting off their access to social services — including housing — for seven to 30 days, but that has rarely happened since Steven Banks was appointed commissioner of the Human Resources Administration – Department of Social Services, which oversees DHS, in 2014, a source said.

The DHS officers interviewed by The Post said their jobs also are severely hindered by chronic understaffing that is prevalent in shelters across the city, including the Parkview Inn, where a resident murdered her boyfriend in 2017.

To bridge the gap, DHS often turns to private security guards to help patrol the shelters — but even some of them apparently can’t be trusted.

In 2017, a security guard at Parkview tried to whack a supervisor with his walkie-talkie after he was caught drunk on the job, DHS said. DHS — which in January 2017 turned over management of its security to the NYPD — said the worker was “promptly suspended” and no longer works at any location.

“Protecting the security of all New Yorkers we serve is our top priority, and through NYPD management of shelter security, shelters citywide are seeing improved reporting, enhanced security, and more effective enforcement,” a DHS spokesman added in a statement to The Post.

“We’re committed to continuing our work with NYPD, at this location and shelters citywide, to ensure that all New Yorkers experiencing homelessness can get back on their feet in a safe, supportive environment.”

NYPD Assistant Commissioner Devora Kaye said Cuesta’s arrest is “an example of a good outcome based on cooperation between the NYPD and DHS.

“We continue to work together to ensure that residents and families are safe in their homes and free from the disorder of criminality,” Kaye said.

Cuesta’s lawyer did not return a request for comment on the drug-possession and intent-to-distribute charges that the suspect faces.

Additional reporting by Oumou Fofana and Aaron Feis