For gay men in the dozens of countries that criminalize their sex lives, social networking can be a blessing or a curse.
High-tech dating apps and social media have enabled countless men to expand their circles of friends and lovers in settings that are hostile to any overt trace of homosexuality. Yet the same technology that they gratefully embrace can expose them to the risk of blackmail, arrest and violence.
In one chilling case earlier this year in Pakistan, police arrested a paramedic on suspicion of killing three men he had met via the gay social network Manjam, which is based in London but has many users in Asia and the Middle East. The suspect told police he considered homosexuality to be evil.
More recently, bloggers and activists raised concerns about how the popular dating app Grindr could be used to pinpoint a user's exact location - even a user living where gay sex is outlawed. After complaints mounted, Grindr announced steps this month to reduce the risks for users in countries with a record of anti-gay violence - including Russia, Egypt, Saudi Arabia, Nigeria, Liberia, Sudan and Zimbabwe.
And during the past week, Grindr posted a warning to its users in Egypt that police - as part of an ongoing crackdown on gays - "may be posing as LGBT to entrap you." The warning urged users to be careful when arranging meetings with strangers.
Grindr's CEO, Joel Simkhai, says his Los Angeles-based company strives to maximize security and privacy for all its users, yet he cautions that governments hostile to gays can muster powerful surveillance resources.
"They have a lot of control and smarts on their side," he said. "We try to use the latest technologies on our end, but so do they, so this tension will continue.
"If your security is a big issue for you," he added, "a location-based service might not be the best option."
The potential perils of social networking have attracted the attention of the International Gay and Lesbian Human Rights Commission, a New York-based watchdog group.
Hossein Alizadeh, the commission's program coordinator for the Middle East and North Africa, said he has tracked two main categories of cases in the region - some in which blackmailers connect with gay men and then threaten to expose them, others in which cyber police and morality police use dating apps and chatroom sites to entrap and arrest gay men.
He cited one recent case in Saudi Arabia involving a man from Jordan who was jailed for eight months, then deported. "No lawyer was willing to defend this poor soul," Alizadeh said.
Another Saudi entrapment case was recounted recently on the blog of Scott Long, founder of the LGBT-rights program at Human Rights Watch who is now based in Cairo as a consultant.
Long posted the account of an Egyptian man in his 30s, working as a pharmacist in Saudi Arabia, who said he was entrapped by Saudi police through use of a gay online chatroom and spent two years in a Jeddah prison cell along with dozens of other men convicted of homosexual acts.
"A lot of them had been arrested on the Internet," the Egyptian man wrote. "The religious police know all the apps and chatrooms. Some of them had got a phone call asking to meet, from someone they'd talked to before on WhatsApp, and that guy turned out to be police."
A guide offering advice on strategies in the event of arrest has been developed by Alizadeh's organization for gays in Iran.
"Even if you are on Grindr or Manjam, in most countries that's not a crime - but sodomy is," Alizadeh said. "There's always an element of deniability. If you have a good lawyer, you can argue, 'How do you prove I'm gay?' But finding a good lawyer is not always possible."
Sharif Mowlabocus, a senior lecturer at the University of Sussex in Britain, is an expert on digital media and LGBT culture who's been closely following the debate over social-networking security. His verdict: Many gay consumers have been naive.
"The service is free or cheap, it is fast, and - for gay men - it allows us to connect with like-minded folk in a way that we've never been able to before," Mowlabocus wrote in an email. "We simply aren't that interested in asking questions of these applications."
Simkhai, the Grindr CEO, called the apps "a lifeline to the gay world" for gays in hostile cultures.
Given such attitudes, Mowlabocus said companies that operate gay dating apps have a duty to protect their users and to be transparent about their security measures.
Should men in countries with anti-gay laws stop using such apps altogether?
Mowlabocus considers that unrealistic. "Add loneliness, isolation, or even desire into the mix and we very quickly begin to see the real benefits outweighing the potential risks."
According to human rights groups, there are more than 70 countries which criminalize gay sex. Gay bars and social clubs either don't exist or operate covertly in such places, which makes dating apps a tempting method for making contacts.
"The lure of being with other people like yourself - it's something people have a deep desire for, even when there are incredible risks," said Andre Banks, executive director of the international gay-rights group All Out.
For location-based dating apps such as Grindr, the security challenges are especially acute because of the very feature that makes them popular. They are designed to help a user make contact with other users in his vicinity - showing their photos and indicating how close they are.
Users' precise locations are not shown during regular use of the app, but controversy arose earlier this year when a Grindr user in Europe was able to determine near-exact whereabouts of thousands of other users, including some in countries with anti-gay laws. This was done via a technique known as trilateration - recording other users' distance from three different locations.
Confronted with criticism, Grindr announced steps this month to reduce the risks for users in countries with a record of anti-gay violence.
"Any user who connects to Grindr is these countries will have their distance hidden automatically by default," the company said.
Launched in 2009, Grindr says it now has about 2.1 million active monthly users in the U.S. and 2.9 million abroad, including many in countries that outlaw gay sex. The company reports about 17,400 average monthly users in the United Arab Emirates and more than 4,200 in Saudi Arabia, for example.
Another globally popular gay dating app, SCRUFF, also has taken steps to address security concerns.
SCRUFF's CEO, Eric Silverberg, said recent technical modifications enable users to continue learning about other users in their vicinity, but seek to thwart any entrapment efforts by refraining from listing the users in order of their proximity.
"I think you'll see both the users and the apps getting smarter," Silverberg said. "It takes both sides."
Launched in 2010 and based in New York City, SCRUFF claims 7 million users, more than half of them outside the U.S.
For users in countries hostile to gays, SCRUFF plans to post country-specific alerts detailing the scope of anti-gay laws. The company also says it will make "hide distance" a default setting in such countries, while warning this may not always guarantee security.
Grindr recently shared with The Associated Press some of the responses it received from an informal survey of users in countries where gay sex is outlawed.
A Venezuelan living in the United Arab Emirates said Grindr was widely used there despite worries that the UAE secret police sometimes create fake Grindr profiles in order to make arrests. He said one acquaintance managed to avoid arrest by paying a bribe, while another served a 3-month jail term before being deported.
A user from Ghana said some of his friends had been beaten and robbed by men they had met on Grindr who had claimed to be gay. Yet he also credited the app for helping him meet some "good guys."