Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
49 lines
2.1 KiB
TypeScript
49 lines
2.1 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
// Spec (admin-portal-i18n): "Catalog Text Is Rendered As Data, Never Markup"
|
|
// -- because catalog values are operator-entered through the /messages
|
|
// management UI, any consumer that injected one via dangerouslySetInnerHTML
|
|
// would open a stored-XSS hole. This scans every real source file under
|
|
// app/ that consumes the i18n module (useT/useLocale/MessagesProvider) and
|
|
// fails if any of them contains dangerouslySetInnerHTML -- a real assertion
|
|
// over the actual consumer surface, not a trust-the-review claim.
|
|
const APP_DIR = path.resolve(__dirname, "..", "..");
|
|
|
|
function collectSourceFiles(dir: string, out: string[] = []): string[] {
|
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
if (entry.name === "node_modules" || entry.name === ".next") continue;
|
|
const full = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
collectSourceFiles(full, out);
|
|
} else if (/\.(ts|tsx)$/.test(entry.name) && !/\.test\.tsx?$/.test(entry.name)) {
|
|
out.push(full);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
const I18N_IMPORT = /from ["']@\/app\/lib\/i18n\/(MessagesProvider|t)["']/;
|
|
|
|
describe("catalog text is never rendered as markup", () => {
|
|
it("no i18n-consuming source file uses dangerouslySetInnerHTML", () => {
|
|
const files = collectSourceFiles(APP_DIR);
|
|
const consumers = files.filter((f) => {
|
|
// The i18n module's own files are not "consumers" of themselves.
|
|
if (path.dirname(f) === path.join(APP_DIR, "lib", "i18n")) return false;
|
|
const src = fs.readFileSync(f, "utf8");
|
|
return I18N_IMPORT.test(src) || /\buseT\(/.test(src) || /\buseLocale\(/.test(src);
|
|
});
|
|
|
|
// Guard against a vacuous pass: this must actually find real consumers
|
|
// (login page, header, root layout) once they are wired to the catalog.
|
|
expect(consumers.length).toBeGreaterThan(0);
|
|
|
|
const offenders = consumers.filter((f) =>
|
|
fs.readFileSync(f, "utf8").includes("dangerouslySetInnerHTML"),
|
|
);
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
});
|