Fear of sexual violence is keeping poor Kenyan women away from communal toilets, and increasing the risk of disease, Amnesty International says.
In a report on Kenya's slums, the human rights group said women and girls were afraid to leave their shacks at night.
As a result they were risking contracting diseases such as dysentery and cholera, the report said.
About 60% of Nairobi residents, about two million people, live in slums with limited access to water and sanitation.
Amnesty criticised a lack of policing in the shantytowns and the government's failure to enforce planning laws and regulations.
It called on the Kenyan government to address violence against women and to ensure women's access to sanitation and public security services.
"Women and girls in Nairobi's slums live under the constant threat of sexual violence," the report said.
"Unable to leave their one-roomed houses after dark, many women in informal settlements resort to 'flying toilets' - using plastic bags thrown from the home to dispose of waste."
Godfrey Odongo, Amnesty's east Africa researcher, said there was "a huge gap between what the government commits to do, and what is going on in the slums every day".
"Kenya's national policies recognise the rights to sanitation and there are laws and standards in place. However, because of decades of failure to recognise slums and informal settlements, planning laws and regulations are not enforced in these areas.
"The lack of enforcement of these laws has ensured that landlords and structure owners in the slums can get away without providing any toilets or shower places for their tenants."
The report, Insecurity and Indignity: Women's experiences in the slums of Nairobi, Kenya, highlights the case of a 19-year-old woman called Amina who was attacked as she walked to a latrine in Nairobi's Mathare slum.
"I always underestimated the threat of violence," she said. "I would go to the latrine any time provided it was not too late."
Four men attacked her in the early evening and were about to rape her when her cries were heard and a group of residents arrived to save her.
In March, trials began of a biodegradable toilet bag it is hoped will replace the flying toilets in Nairobi's largest slum of Kibera.
The "Peepoo" bag is coated with a chemical which turns human waste into fertiliser.
Dickson Matu Makau, who was in charge of distributing and collecting the used bags, told the BBC's Network Africa programme that the Peepoo proved popular and was much preferred to normal polythene bags.
Analysts predict the population of Nairobi will swell to about six million by 2025.