feat: harden atoms-nexst against review findings (37 items)
Gitea Actions Runner Test / test-job (push) Successful in 2s
CI / check (push) Successful in 30s
CI / tests-integration (push) Successful in 1m42s
CI / tests-unit (push) Failing after 1m49s
CI / tests-ui (push) Successful in 2m31s
CI / preflight (push) Skipped
CI / deploy (push) Skipped
Gitea Actions Runner Test / test-job (push) Successful in 2s
CI / check (push) Successful in 30s
CI / tests-integration (push) Successful in 1m42s
CI / tests-unit (push) Failing after 1m49s
CI / tests-ui (push) Successful in 2m31s
CI / preflight (push) Skipped
CI / deploy (push) Skipped
Second review pass covering security, performance, admin tooling and the public/room flows. All HIGH and MEDIUM findings from the audit are resolved; nothing in this commit changes the visible feature set. Authentication & session security - CSP is now set on the request headers in the proxy, which is what Next.js uses to derive the render nonce, so the nonce is effective. - 2FA: an already-enabled user cannot re-enroll, the setup endpoint is rate-limited per account, and confirmed codes are persisted so the second secret no longer silently never applies. - Password reset revokes the ticket, authTicket and all personal access tokens, and bumps the token version so existing sessions die. The same revocation is now wired into the staff-side password reset. - /reset and /verify return a stable error code instead of raw text; the mail lookups are ordered by id so duplicates cannot vary between runs. - Resending the verification mail gets a per-address cooldown on top of the per-user limit. - Issue API tokens with the narrower radio/ticket ability set instead of "*". Authorization & input handling - Mid-rank staff can no longer keep dynamically granted non-view admin.* permissions: existing grants are revoked by migration and the grant lookup is restricted to "%.view". Rank guards use the dynamic super-admin check. - Alerting a user is permission-checked and audited like the other tools. - Material mutations (giveCredits/giveDuckets/giveDiamonds, the admin user actions route, bulk user actions) are capped and rank-guarded, and bulk ids are bounded. - updateRoom / updateRoomItem write through a field allowlist, and items may only be edited through their own room. - Classnames reaching the filesystem are validated before use so a crafted value cannot escape the asset directories. - The word filter now also covers offline mails, guild forum threads and replies, and user mottos. - Media uploads are validated by magic bytes, /api/media requires the page edit permission, APP_URL must be configured once mail is enabled, and the diagnostics error route checks the fetch site header. Admin tooling - Secret settings render masked and cannot be overwritten with a blank or an arbitrary raw key; radio credentials are new password inputs. - Commandocentrum balance changes are audited. - Admin list pagination reads the caller's per-page instead of the max, and the log exporter caps offset and search length. Performance - Catalog translations are cached per module, with a cheap revision hash; the public online count uses a stale window instead of hammering the DB. - The cache warmup now primes the payload the home route actually reads. - TopHeader batches its queries into one round trip, and LCP avatars load eagerly. - motion/react and sonner are no longer part of the root layout; the nav dropdown and mobile nav panels are lazy client chunks. Anonymous visitors again get the navigation chrome, and public pages get an edge cacheable response. Accessibility - Nested <main> elements in phase pages became <section>; the page entrance and route progress animations are pure CSS that respect reduced motion.
This commit is contained in:
1 parent
3933214953
commit
6cc45d7413
150 files changed
+2137
-759
No files matched your search
@@ -5,7 +5,7 @@ import { invalidateCatalogTotals } from "@/features/catalog/server/catalog-total
|
||||
import { apiError, apiOk } from "@/lib/api";
|
||||
import { withAdmin } from "@/lib/api-handler";
|
||||
import { db, ItemsBase, queryRows } from "@/lib/db";
|
||||
import { normalizeClassname } from "@/lib/furni/classname";
|
||||
import { isSafeAssetName, normalizeClassname } from "@/lib/furni/classname";
|
||||
import { localFurnitureStatus } from "@/lib/furni/local-presence";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { logAudit } from "@/lib/services/audit";
|
||||
@@ -709,9 +709,20 @@ export const PATCH = withAdmin(
|
||||
[];
|
||||
|
||||
for (const item of items) {
|
||||
const starIdx = item.classname.indexOf("*");
|
||||
const normalised = item.classname.trim();
|
||||
// The classname is joined straight into a `.nitro` file path, so a
|
||||
// separator/looking payload must never get that far.
|
||||
if (!isSafeAssetName(normalised)) {
|
||||
results.push({
|
||||
classname: item.classname,
|
||||
ok: false,
|
||||
warning: "Invalid classname",
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const starIdx = normalised.indexOf("*");
|
||||
const baseClassname =
|
||||
starIdx !== -1 ? item.classname.substring(0, starIdx) : item.classname;
|
||||
starIdx !== -1 ? normalised.substring(0, starIdx) : normalised;
|
||||
const nitroPath = path.join(
|
||||
/*turbopackIgnore: true*/ nitroDir,
|
||||
`${baseClassname}.nitro`,
|
||||
|
||||
@@ -6,11 +6,20 @@ import { PERMS } from "@/lib/permissions";
|
||||
import { rcon } from "@/lib/services/rcon";
|
||||
import { logStaffActivity } from "@/lib/services/staff-activity";
|
||||
|
||||
/** Currency grants are capped: an unbounded `amount` minted an economy-breaking
|
||||
* balance with a single request. */
|
||||
function positiveAmount(amount: number): boolean {
|
||||
return Number.isInteger(amount) && amount > 0 && amount <= MAX_CURRENCY_GRANT;
|
||||
}
|
||||
|
||||
const MAX_CURRENCY_GRANT = 1_000_000;
|
||||
|
||||
export const POST = withAdmin(
|
||||
{ permission: PERMS.USERS_EDIT },
|
||||
async (request, context) => {
|
||||
const staffId = context.session.user.id;
|
||||
const staffRank = context.session.user.rank;
|
||||
const isSuper = context.permissions.isSuperAdmin;
|
||||
const formData = await request.formData();
|
||||
const userId = Number(formData.get("userId"));
|
||||
const username = String(formData.get("username") || "");
|
||||
@@ -23,6 +32,33 @@ export const POST = withAdmin(
|
||||
);
|
||||
}
|
||||
|
||||
// Every branch below acts on a live account, so the rank guard that the
|
||||
// set_rank branch already applies belongs to all of them: staff may not
|
||||
// act on users at or above their own rank unless they are the hotel's
|
||||
// dynamic owner.
|
||||
if (action !== "set_rank") {
|
||||
const [target] = await db
|
||||
.select({ rank: User.rank })
|
||||
.from(User)
|
||||
.where(eq(User.id, userId))
|
||||
.limit(1);
|
||||
if (!target) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "User not found" },
|
||||
{ status: 404 },
|
||||
);
|
||||
}
|
||||
if (!isSuper && target.rank >= staffRank) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Cannot act on a user at or above your rank",
|
||||
},
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (action === "set_rank") {
|
||||
const rank = Number(formData.get("rank") || "0");
|
||||
if (!Number.isInteger(rank) || rank < 1) {
|
||||
@@ -141,7 +177,7 @@ export const POST = withAdmin(
|
||||
|
||||
if (action === "give_credits") {
|
||||
const credits = Number(formData.get("credits") || "0");
|
||||
if (!credits || credits <= 0) {
|
||||
if (!positiveAmount(credits)) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Invalid credit amount" },
|
||||
{ status: 400 },
|
||||
@@ -166,7 +202,7 @@ export const POST = withAdmin(
|
||||
|
||||
if (action === "give_duckets") {
|
||||
const amount = Number(formData.get("amount") || "0");
|
||||
if (!amount || amount <= 0) {
|
||||
if (!positiveAmount(amount)) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Invalid duckets amount" },
|
||||
{ status: 400 },
|
||||
@@ -188,7 +224,7 @@ export const POST = withAdmin(
|
||||
|
||||
if (action === "give_diamonds") {
|
||||
const amount = Number(formData.get("amount") || "0");
|
||||
if (!amount || amount <= 0) {
|
||||
if (!positiveAmount(amount)) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Invalid diamonds amount" },
|
||||
{ status: 400 },
|
||||
@@ -213,7 +249,7 @@ export const POST = withAdmin(
|
||||
|
||||
if (action === "give_points") {
|
||||
const amount = Number(formData.get("amount") || "0");
|
||||
if (!amount || amount <= 0) {
|
||||
if (!positiveAmount(amount)) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Invalid points amount" },
|
||||
{ status: 400 },
|
||||
|
||||
Reference in new issue
Block a user