Facebook knows almost everything about you and uses that to show ads designed to appeal to your interests.

That's nothing new. But on Friday, a report surfaced that these targeted ads can potentially be used illegally.

Facebook has an ad customization option called "Ethnic Affinities," which lets advertisers target specific groups -- or exclude them. ProPublica found that the tool can be used to discriminate against users with housing-related ads -- which is forbidden under the Fair Housing Act.

Facebook (FB) doesn't ask users for their race, but the massive amounts of data it collects can infer it.

ProPublica tested this feature by posting an ad for a housing event that it requested not be shown to anyone with an "Ethnic Affinity" of African-American, Asian-American or Hispanic. It said that the ad was approved in 15 minutes.

The 1968 Fair Housing Act prohibits advertising the rental or sale of homes and discriminating "based on race, color, religion, sex, handicap, familial status, or national origin."

Related: Mark Zuckerberg breaks his silence about Peter Thiel

Since the ProPublica ad was for an event, not actually selling a house, it wasn't technically illegal. But civil rights attorney John Relman, who called the exclusionary ads "horrifying," told CNNMoney there are numerous non-discrimination laws at both the federal and local level that could potentially be violated with ads that exclude minorities.

"The problem is when Facebook develops a tool like that ... if it's an advertiser who's working in a part of the market covered by discrimination laws, like the housing market, then Facebook is going to be liable for discrimination," Relman said.

Facebook screens and approves all ads using both humans and algorithms. It could easily miss one that's discriminatory.

"[Facebook] realizes it's a powerful tool being able to sort people based on race or gender," Relman said. "But this can be used in insidious ways to exclude people and it's a very dangerous practice."

Related: Facebook will show you ads even if you use ad blockers

Any advertiser can exclude certain "Ethnic Affinities" by clicking "exclude people" on the ad creation page.

Facebook says the ad targeting options are meant to let advertisers granularly target only those individuals who would be interested in the product.

Christian Martinez, head of multicultural at Facebook, defended the use of ad targeting based on Ethnic Affinities in a blog post published after the ProPublica report.

Martinez said Facebook wants its users to see ads that are specifically relevant to them -- that this is a way of acknowledging and embracing diversity.

"Everyone benefits from access to content that's more relevant to them. But this is especially critical for people who choose to affiliate with ethnic communities," he wrote.

So-called "exclusion targeting" is common in the advertising industry, he said, when Facebook sees published ads that violate the rules, it promptly removes them.

In a statement, a spokeswoman for Facebook confirmed the company prohibits people from using ads to discriminate: "Our policies prohibit using our targeting options to discriminate, and they require compliance with the law. We take prompt enforcement action when we determine that ads violate our policies."

This type of ad targeting is not used by Google (GOOG), which allows exclusionary advertising based on age, gender, and parental status, but not race or ethnicity.