-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a NSFW protection #520
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall lgtm - thanks! We may want more classifiers in the future, and supporting that looks easy.
src/protections/NsfwProtection.ts
Outdated
const isMedia = msgtype === 'm.image' || formattedBody.toLowerCase().includes('<img'); | ||
|
||
if (isMedia) { | ||
const mxc = content["url"] | ||
const image = await mjolnir.client.downloadContent(mxc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this break if there is an event with msgtype !== m.image
and an img tag in the html? As now content['url']
is undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likely, yea. I think we should just remove the formatted body condition for now - parsing the HTML can be a future PR.
src/protections/NsfwProtection.ts
Outdated
const isMedia = msgtype === 'm.image' || formattedBody.toLowerCase().includes('<img'); | ||
|
||
if (isMedia) { | ||
const mxc = content["url"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldnt the thumbnail be checked as well? It might be a different image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, though thumbnails are a bit weird already. This can be revisted in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it helps this is how i've laid out Draupnir's attempt to copy this protection, so that it's possible to scrape out more urls from the message https://github.com/the-draupnir-project/Draupnir/blob/gnuxie/nsfwjs/src/protections/NSFWImageProtection.tsx#L55-L71 (incomplete code though, would like to avoid depending on @tensorflow/tfjs-node
)
import { Mjolnir } from "../Mjolnir"; | ||
import * as nsfw from 'nsfwjs'; | ||
import {LogLevel} from "matrix-bot-sdk"; | ||
import { node } from '@tensorflow/tfjs-node'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will pull in over 285MB
of dependencies btw, which is more weight than the entire mjolnir docker image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Image size isn't really a concern here, but if you're aware of alternatives, we can certainly consider them.
Adds a protection which utilizes https://github.com/infinitered/nsfwjs to determine if images sent into a protected room are NSFW. If so, mjolnir automatically redacts the image.
Also adds a config option to manually set the sensitivity of the protection.