make eval unable to return sensitive strings

This commit is contained in:
Lio Young 2021-04-10 23:27:27 +02:00
parent 80574888d1
commit b8c58708f5
No known key found for this signature in database
GPG Key ID: 789795A11879E169
3 changed files with 29 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import { Context } from "../../utils/types";
import Command from "../../handler/structures/Command";
import clean from "../../utils/clean"
export = class Eval extends Command {
constructor() {
super({
@ -15,16 +16,16 @@ export = class Eval extends Command {
})
}
async command(ctx: any) {
async command(ctx: Context) {
let code = ctx.args.join(" ")
try {
let evaled = await eval(code)
if (typeof evaled != 'string') {
evaled = (await import("util")).inspect(evaled, false, 1)
}
return evaled
return ctx.channel.send(`\`\`\`js\n${clean(evaled)}\n\`\`\``)
} catch (error) {
console.error(error)
}
}
}

23
src/utils/clean.ts Normal file
View File

@ -0,0 +1,23 @@
import config from '../../config'
import replace from './replace'
let SensitiveStrings = [
config.token,
config.supabase.key,
config.supabase.url,
config.apis.sheri,
config.apis.yiffrest,
].flat(Infinity)
export default function clean(content: any) {
let type = content
if (typeof type === 'object') {
content = JSON.stringify(content)
}
let regex = new RegExp(`(${SensitiveStrings.join("|")})`, "gi")
content = replace(regex, "*snip*", content)
if (typeof type === 'object') {
content = JSON.parse(content)
}
return content
}

View File

@ -1,4 +1,4 @@
export default function replace(to_replace: string, replace_with: string, full_string: string) {
export default function replace(to_replace: any, replace_with: string, full_string: string) {
return full_string.replace(to_replace, replace_with)
}