From 5072cee519ea5773db3f6a0639daf62021ac4793 Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Thu, 8 Oct 2026 00:05:18 +0200 Subject: [PATCH] Send the osTicket ticket text as base64, not percent-encoded A test ticket sent to a real osTicket arrived with every space shown as %20. osTicket takes the message's type from an RFC 2397 data URL and strips the "data:" part, but leaves percent-encoded text as it is. The message is now sent as base64 (data:text/plain;charset=utf-8;base64,...), which osTicket decodes (it is how it takes attachments), and which works whether or not a given osTicket version decodes percent-encoding. The stand-in osTicket in the test had decoded the percent-encoding, which is why this wasn't caught: the test now requires base64 and fails if any percent-encoding is in the message. INTEGRATIONS.md says the ticket API is only partly verified against a real osTicket, and what that first test showed. Co-Authored-By: Claude Sonnet 5.5 --- INTEGRATIONS.md | 10 ++++++---- server/src/integrations/osticket/ticketApi.ts | 5 +++-- server/test/alertTickets.test.ts | 8 +++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/INTEGRATIONS.md b/INTEGRATIONS.md index de87e45..b6c85f5 100644 --- a/INTEGRATIONS.md +++ b/INTEGRATIONS.md @@ -162,10 +162,12 @@ the dashboard views themselves load fine. "user" is this app, so an acknowledgement would only bounce) and osTicket's own staff alert on or off as you choose. - **What it can't do:** close, reopen, or comment on a ticket — osTicket's API has no such endpoint. A ticket opened here is yours to close in osTicket. -- **Not verified against a real osTicket** — built from osTicket's published API documentation and tested against a - stand-in server that checks what is sent (the key header, the JSON fields, the message encoding, and how each - answer — created, refused key, bad request, redirect — is handled). If osTicket rejects a ticket, "Send a test - ticket" shows the reason it gave. +- **Only partly verified against a real osTicket.** It was built from osTicket's published API documentation and + tested against a stand-in server that checks what is sent (the key header, the JSON fields, the message encoding, + and how each answer — created, refused key, bad request, redirect — is handled). The first test ticket sent to a + real osTicket arrived with every space shown as `%20`: osTicket takes the message from a `data:` URL but does not + decode percent-encoding, so the message is now sent as base64, which it does decode (not yet re-checked against a + real osTicket). If osTicket rejects a ticket, "Send a test ticket" shows the reason it gave. ### phpIPAM diff --git a/server/src/integrations/osticket/ticketApi.ts b/server/src/integrations/osticket/ticketApi.ts index b77cd2b..c75dab1 100644 --- a/server/src/integrations/osticket/ticketApi.ts +++ b/server/src/integrations/osticket/ticketApi.ts @@ -106,8 +106,9 @@ export function createOsTicketTicketApi(config: OsTicketApiConfig) { name: ticket.name, email: ticket.email, subject: ticket.subject, - // osTicket reads the type of the message from an RFC 2397 data URL. - message: `data:text/plain;charset=utf-8,${encodeURIComponent(ticket.message)}`, + // osTicket reads the type of the message from an RFC 2397 data URL. Base64, not percent-encoding: osTicket strips the + // "data:" part but leaves percent-encoded text as it is (a test ticket arrived full of %20), while base64 is decoded. + message: `data:text/plain;charset=utf-8;base64,${Buffer.from(ticket.message, "utf8").toString("base64")}`, ...(ticket.topicId ? { topicId: ticket.topicId } : {}), ...(ticket.priorityId ? { priority: ticket.priorityId } : {}), }); diff --git a/server/test/alertTickets.test.ts b/server/test/alertTickets.test.ts index 9cc0ddc..d97d7bc 100644 --- a/server/test/alertTickets.test.ts +++ b/server/test/alertTickets.test.ts @@ -229,9 +229,11 @@ describe("osTicket API client", () => { assert.equal(s.body.source, "API"); assert.equal(s.body.alert, true); assert.equal(s.body.autorespond, false, "an acknowledgement to the app's own address would only bounce"); - // osTicket reads a message's type from an RFC 2397 data URL; decoded it must be exactly what was written - assert.match(s.body.message, /^data:text\/plain;charset=utf-8,/); - assert.equal(decodeURIComponent(s.body.message.replace(/^data:text\/plain;charset=utf-8,/, "")), "Line one\nLine two — åäö ✓"); + // osTicket reads a message's type from an RFC 2397 data URL. It must be base64: osTicket leaves percent-encoded text as it is, + // which put "%20" in place of every space in a real ticket. + assert.match(s.body.message, /^data:text\/plain;charset=utf-8;base64,[A-Za-z0-9+/=]+$/); + assert.doesNotMatch(s.body.message, /%[0-9A-Fa-f]{2}/, "percent-encoding ends up in the ticket as literal text"); + assert.equal(Buffer.from(s.body.message.replace(/^data:text\/plain;charset=utf-8;base64,/, ""), "base64").toString("utf8"), "Line one\nLine two — åäö ✓"); }); test("topic and priority are sent only when set; staff alerts can be switched off", async () => {