Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix charset
Thiago Araujo da Silvaf9d9f4e1ec53
diff --git a/backend/src/server/plugins/swagger.test.ts b/backend/src/server/plugins/swagger.test.tsindex b9b40fafe8..70d88534a3 100644--- a/backend/src/server/plugins/swagger.test.ts+++ b/backend/src/server/plugins/swagger.test.ts@@ -130,11 +130,27 @@ describe("OpenAPI spec routes", () => {expect(second.headers.etag).toBe(first.headers.etag);});+ test("keeps the exact content types @fastify/swagger-ui sent, charset included", async () => {+ const json = await getSpec();+ const yamlRes = await getSpec({}, "/api/docs/yaml");++ // A consumer comparing the header exactly must not notice the handler swap.+ expect(json.headers["content-type"]).toBe("application/json; charset=utf-8");+ expect(yamlRes.headers["content-type"]).toBe("application/x-yaml");+ });++ test("still answers HEAD", async () => {+ const res = await app.inject({ method: "HEAD", url: "/api/docs/json" });++ expect(res.statusCode).toBe(200);+ expect(res.headers["content-type"]).toBe("application/json; charset=utf-8");+ });+test("serves the yaml spec the same way", async () => {const res = await getSpec({ "accept-encoding": "br" }, "/api/docs/yaml");expect(res.statusCode).toBe(200);- expect(res.headers["content-type"]).toBe("application/x-yaml; charset=utf-8");+ expect(res.headers["content-type"]).toBe("application/x-yaml");expect(brotliDecompressSync(res.rawPayload).toString("utf8")).toContain("openapi:");});diff --git a/backend/src/server/plugins/swagger.ts b/backend/src/server/plugins/swagger.tsindex 79597f98e7..6ec5e37ca7 100644--- a/backend/src/server/plugins/swagger.ts+++ b/backend/src/server/plugins/swagger.ts@@ -34,7 +34,7 @@ const SPEC_FORMAT_BY_ROUTE: Record<string, SpecFormat> = {const buildSpecPayload = async (fastify: FastifyInstance, format: SpecFormat): Promise<SpecPayload> => {const isYaml = format === "yaml";const body = isYaml ? fastify.swagger({ yaml: true }) : JSON.stringify(fastify.swagger());- const contentType = isYaml ? "application/x-yaml; charset=utf-8" : "application/json; charset=utf-8";+ const contentType = isYaml ? "application/x-yaml" : "application/json; charset=utf-8";const identity = Buffer.from(body, "utf8");