Skip to content

Commit c2288ae

Browse files
Validates submittal project and item IDs
Adds validation to ensure project and item IDs are properly formatted UUIDs and do not contain path traversal tokens. This prevents potential security vulnerabilities and ensures data integrity.
1 parent 63f5612 commit c2288ae

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/aps-submittals-helpers.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,34 @@ export function summarizeSubmittalAttachments(raw: unknown): {
218218

219219
// ── Submittal‑specific validation ────────────────────────────────
220220

221+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
222+
223+
function containsTraversalTokens(value: string): boolean {
224+
return (
225+
value.includes("/") ||
226+
value.includes("\\") ||
227+
value.toLowerCase().includes("%2f") ||
228+
value.includes("..")
229+
);
230+
}
231+
221232
export function validateSubmittalProjectId(id: string): string | null {
222233
if (!id) return "project_id is required.";
223-
// Accept both 'b.uuid' (DM format) and plain UUID (ACC format)
234+
if (containsTraversalTokens(id))
235+
return "project_id contains disallowed characters ('/', '\\', '%2F', or '..').";
236+
// Accept 'b.<uuid>' (DM format) or plain UUID (ACC format)
237+
const bare = id.startsWith("b.") ? id.slice(2) : id;
238+
if (!UUID_RE.test(bare))
239+
return "project_id must be a UUID (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) optionally prefixed with 'b.'.";
224240
return null;
225241
}
226242

227243
export function validateSubmittalItemId(id: string): string | null {
228244
if (!id) return "item_id is required.";
245+
if (containsTraversalTokens(id))
246+
return "item_id contains disallowed characters ('/', '\\', '%2F', or '..').";
247+
if (!UUID_RE.test(id))
248+
return "item_id must be a UUID (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).";
229249
return null;
230250
}
231251

0 commit comments

Comments
 (0)