Remove webhook tokens from error messages
This commit is contained in:
@@ -94,6 +94,11 @@ function printError(type, source, e, payload) {
|
|||||||
console.dir(payload, {depth: null})
|
console.dir(payload, {depth: null})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param {string} stack */
|
||||||
|
function cleanErrorStack(stack) {
|
||||||
|
return stack.replace(/(\/webhooks\/[0-9]+\/)[a-zA-Z0-9_-]+/g, "$1(redacted)")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} roomID
|
* @param {string} roomID
|
||||||
* @param {"Discord" | "Matrix"} source
|
* @param {"Discord" | "Matrix"} source
|
||||||
@@ -134,7 +139,7 @@ async function sendError(roomID, source, type, e, payload) {
|
|||||||
builder.addLine(errorIntroLine)
|
builder.addLine(errorIntroLine)
|
||||||
|
|
||||||
// Where
|
// Where
|
||||||
const stack = stringifyErrorStack(e)
|
const stack = cleanErrorStack(stringifyErrorStack(e))
|
||||||
builder.addLine(`Error trace:\n${stack}`, tag`<details><summary>Error trace</summary><pre>${stack}</pre></details>`)
|
builder.addLine(`Error trace:\n${stack}`, tag`<details><summary>Error trace</summary><pre>${stack}</pre></details>`)
|
||||||
|
|
||||||
// How
|
// How
|
||||||
@@ -502,5 +507,6 @@ async event => {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
module.exports.stringifyErrorStack = stringifyErrorStack
|
module.exports.stringifyErrorStack = stringifyErrorStack
|
||||||
|
module.exports.cleanErrorStack = cleanErrorStack
|
||||||
module.exports.sendError = sendError
|
module.exports.sendError = sendError
|
||||||
module.exports.printError = printError
|
module.exports.printError = printError
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const {test} = require("supertape")
|
const {test} = require("supertape")
|
||||||
const {stringifyErrorStack} = require("./event-dispatcher")
|
const {stringifyErrorStack, cleanErrorStack} = require("./event-dispatcher")
|
||||||
|
|
||||||
test("stringify error stack: works", t => {
|
test("stringify error stack: works", t => {
|
||||||
function a() {
|
function a() {
|
||||||
@@ -21,3 +21,30 @@ test("stringify error stack: works", t => {
|
|||||||
t.match(str, /^ \[prop\]: 2.1$/m)
|
t.match(str, /^ \[prop\]: 2.1$/m)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("clean error stack: removes webhook token", t => {
|
||||||
|
t.notMatch(
|
||||||
|
cleanErrorStack(`
|
||||||
|
DiscordAPIError: Service resource is being rate limited.
|
||||||
|
at fn (/var/home/cadence/out-of-your-element/node_modules/snowtransfer/src/RequestHandler.ts:591:13)
|
||||||
|
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
|
||||||
|
at exports.RequestHandler.request (/var/home/cadence/out-of-your-element/node_modules/snowtransfer/src/RequestHandler.ts:546:17)
|
||||||
|
at WebhookMethods.executeWebhook (/var/home/cadence/out-of-your-element/node_modules/snowtransfer/src/methods/Webhook.ts:249:35)
|
||||||
|
at /var/home/cadence/out-of-your-element/src/m2d/actions/channel-webhook.js:65:31
|
||||||
|
at withWebhook (/var/home/cadence/out-of-your-element/src/m2d/actions/channel-webhook.js:47:9)
|
||||||
|
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
|
||||||
|
at async Object.sendMessageWithWebhook (/var/home/cadence/out-of-your-element/src/m2d/actions/channel-webhook.js:64:17)
|
||||||
|
at async Object.sendEvent (/var/home/cadence/out-of-your-element/src/m2d/actions/send-event.js:132:27)
|
||||||
|
at async /var/home/cadence/out-of-your-element/src/m2d/event-dispatcher.js:208:27
|
||||||
|
at async AppService.<anonymous> (/var/home/cadence/out-of-your-element/src/m2d/event-dispatcher.js:162:11) {
|
||||||
|
[method]: "POST"
|
||||||
|
[path]: "/webhooks/1160903754728611841/pfRqHl9vVZImdqwWWSZxxH8T-JJMnauxroMnHsvC6ARA-3B9_STH_bnHB9pd7QQaUVCG"
|
||||||
|
[code]: 40062
|
||||||
|
[httpStatus]: 429
|
||||||
|
[request]: {"endpoint":"/webhooks/1160903754728611841/pfRqHl9vVZImdqwWWSZxxH8T-JJMnauxroMnHsvC6ARA-3B9_STH_bnHB9pd7QQaUVCG","method":"POST","dataType":"json","data":{"content":"https://discordstatus.com/#day\nOnly what discord tell us right now","allowed_mentions":{"parse":["roles"],"users":[]},"username":"lewri","avatar_url":"https://bridge.cadence.moe/download/matrix/matrix.org/URWwrtSUONGOYhfMsdUzcrir"}}
|
||||||
|
[response]: {}
|
||||||
|
[name]: "DiscordAPIError"`
|
||||||
|
),
|
||||||
|
/pfRqHl9v/
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user