← Blog

Claude skill multipart upload security in MCP CI/CD pipelines — SA-SKL-MULTIPART4

MCP skills that accept ZIP archives, source code bundles, or configuration files in CI/CD pipeline integrations rely on multipart form uploads. The multipart parsing layer — typically busboy or multer — has four distinct attack surfaces: field count before any limits are enforced, filename parsing with null byte injection, disk allocation before validation, and chunk reassembly under concurrent uploads. SA-SKL-MULTIPART4 covers all four, with concrete vulnerable and fixed code examples for each.

By SkillAudit  |  7 Nov 2026

MULTIPART4-001 — Missing field-count limit causes OOM via 100k form fields

Busboy and multer both iterate over multipart fields sequentially, calling the field event handler for each one. Without a field-count limit, an attacker constructs a multipart body with 100,000 or more form fields — each with a small name and value — and submits it in a single request. Busboy does not reject the body until it finishes parsing all fields (or times out). The Node.js heap accumulates all field names and values in memory during parsing. For 100,000 fields of 100 bytes each, that is 10 MB per request — multiplied across concurrent requests from the attacker, this can exhaust the heap and crash the process. The multer limits.fields option (and busboy's equivalent) sets a maximum field count and aborts parsing as soon as it is exceeded, so only the first N fields are iterated — the rest of the request body is discarded without being read into memory.

// VULNERABLE — MULTIPART4-001
// upload-handler.js — multer with no field count limit
import multer from 'multer';

const upload = multer({
  dest: '/tmp/uploads/',
  limits: {
    fileSize: 10 * 1024 * 1024, // 10 MB file size limit (correct)
    // BUG: no limits.fields — attacker sends 100,000 fields
    // multer iterates all 100k fields into memory before fileSize check runs
  },
});

app.post('/upload/skill-zip', upload.single('file'), (req, res) => {
  // By the time this handler runs, 100k fields are already in memory
  res.json({ ok: true });
});

// Attack: multipart body with 100,000 fields before the file part
// curl -F "a=1&b=2&c=3...&field99999=x&file=@payload.zip" https://skill.example.com/upload/skill-zip
// FIXED — MULTIPART4-001: set limits.fields (and other limits) explicitly
const upload = multer({
  dest: '/tmp/uploads/',
  limits: {
    fileSize:   10 * 1024 * 1024, // 10 MB per file
    files:      1,                // Only 1 file per request
    fields:     20,               // At most 20 non-file form fields
    fieldNameSize: 100,           // Max 100 bytes for a field name
    fieldSize:  10 * 1024,        // Max 10 KB for a non-file field value
    parts:      22,               // Total parts (fields + files) ≤ 22
  },
});

// For busboy directly (without multer):
import Busboy from 'busboy';
app.post('/upload/skill-zip', (req, res) => {
  const busboy = Busboy({
    headers: req.headers,
    limits: {
      files:      1,
      fileSize:   10 * 1024 * 1024,
      fields:     20,          // busboy aborts with LIMIT_FIELD_COUNT after 20 fields
      fieldNameSize: 100,
      fieldSize:  10 * 1024,
    },
  });
  let fieldCount = 0;
  busboy.on('field', (name, value) => {
    fieldCount++;
    if (fieldCount > 20) { req.unpipe(busboy); res.status(400).json({ error: 'Too many fields' }); }
    // process field
  });
  req.pipe(busboy);
});
HIGH
SA-SKL-MULTIPART4-001 — Multer or busboy without a limits.fields setting iterates 100,000+ attacker-supplied form fields into memory before any rejection logic runs — consuming the Node.js heap across concurrent requests and crashing the process (DoS); fix by setting limits.fields (multer) or the busboy limits.fields option to a small number (≤20 for typical upload forms) so parsing aborts immediately on the N+1 field. Detection: SkillAudit flags multer({ limits: { ... } }) configurations that omit fields from the limits object, and Busboy({ limits: { ... } }) configurations without a fields limit.

MULTIPART4-002 — Null byte in multipart Content-Disposition filename bypasses extension check

The HTTP multipart Content-Disposition header carries the filename parameter as a quoted string. An attacker constructs a filename containing a null byte (ASCII 0x00) followed by an allowed extension: filename="evil.sh\x00.zip". Node.js string processing reads the entire filename including the null byte and the .zip suffix, so the extension check (path.extname(filename) === '.zip') passes. But on some Linux systems, when Node.js calls into native OS functions (such as rename(), open(), or external tools invoked via child_process.exec()`), strings are passed to libc as C-style null-terminated strings. The libc function sees evil.sh and stops at the null byte — the .zip suffix is invisible to the OS. The file is stored as evil.sh and may be executed if it lands in an executable location. Multer's default filename sanitization does not strip null bytes. The fix is to strip or reject any filename containing a null byte or other control characters before extension validation.

// VULNERABLE — MULTIPART4-002
// File extension check passes because Node.js string includes the full filename
import path from 'path';
import multer from 'multer';

const upload = multer({
  storage: multer.diskStorage({
    destination: '/tmp/uploads/',
    filename: (req, file, cb) => {
      // file.originalname from busboy — may contain null bytes
      const ext = path.extname(file.originalname); // path.extname('evil.sh\x00.zip') → '.zip'
      if (ext !== '.zip') {
        return cb(new Error('Only .zip files allowed'));
      }
      // Extension check passes — file saved as 'evil.sh\x00.zip'
      // On some OS calls: null byte truncates to 'evil.sh'
      cb(null, file.originalname);
    },
  }),
});

// Attack: multipart body with:
// Content-Disposition: form-data; name="file"; filename="evil.sh�.zip"
// FIXED — MULTIPART4-002: strip null bytes and control characters before filename use
import path from 'path';
import { randomUUID } from 'crypto';

function sanitizeFilename(rawName) {
  if (!rawName) return 'upload';
  // Remove null bytes and other ASCII control characters (0x00–0x1F, 0x7F)
  const stripped = rawName.replace(/[\x00-\x1f\x7f]/g, '');
  // Remove path traversal sequences
  const basename = path.basename(stripped);
  // Allow only alphanumeric, dash, underscore, dot
  return basename.replace(/[^a-zA-Z0-9._-]/g, '_').slice(0, 128) || 'upload';
}

const upload = multer({
  storage: multer.diskStorage({
    destination: '/tmp/uploads/',
    filename: (req, file, cb) => {
      const safeName = sanitizeFilename(file.originalname);
      const ext = path.extname(safeName).toLowerCase();
      if (ext !== '.zip') {
        return cb(new Error('Only .zip files allowed'));
      }
      // Use UUID-prefixed filename to prevent any remaining collision or guessing
      cb(null, `${randomUUID()}${ext}`);
    },
  }),
  limits: { fileSize: 10 * 1024 * 1024, fields: 5, files: 1 },
});
HIGH
SA-SKL-MULTIPART4-002 — A filename containing a null byte (\x00) followed by an allowed extension passes Node.js extension checks (which see the full string) but truncates at the null byte in libc OS calls — the file may be stored and potentially executed under the pre-null-byte name (evil.sh instead of evil.sh.zip); fix by stripping all null bytes and ASCII control characters from filenames before any extension validation, using a UUID-based server-side filename for storage rather than the client-supplied name. Detection: SkillAudit flags path.extname(file.originalname) calls without a preceding step that removes null bytes or non-printable characters from the filename string.

MULTIPART4-003 — Upload stored to temp disk before MIME and size validation

Multer's default disk storage writes the entire multipart file to the temp directory before the route handler runs — before any MIME type check, before any size check that the application code performs (as opposed to the limits.fileSize option, which does apply during streaming). When a skill enforces a 10 MB upload limit via application-level code that runs in the route handler rather than via limits.fileSize, an attacker can upload a 2 GB file. Multer streams it entirely to disk, consuming 2 GB of the temp partition, before the route handler rejects it. If 10 concurrent requests each upload 2 GB, the temp partition fills (20 GB) before any rejection handler runs. The fix is to set limits.fileSize in the multer or busboy options — this limit applies during streaming and aborts the request as soon as the byte count exceeds the limit, before the full file is written.

// VULNERABLE — MULTIPART4-003
// Application-level size check runs AFTER the file is fully written to disk
import multer from 'multer';
import fs from 'fs';

const upload = multer({ dest: '/tmp/uploads/' }); // No limits.fileSize — writes full file

app.post('/upload/skill-zip', upload.single('file'), (req, res) => {
  // By this point the file is ALREADY on disk — could be 2 GB
  const stat = fs.statSync(req.file.path);
  if (stat.size > 10 * 1024 * 1024) {
    fs.unlinkSync(req.file.path); // Delete the already-written 2 GB file
    return res.status(413).json({ error: 'File too large' });
  }
  // process req.file
});

// Attack: upload 2 GB × 10 concurrent → 20 GB disk consumed before any rejection
// FIXED — MULTIPART4-003: limits.fileSize applied during streaming — aborts before full write
import multer from 'multer';

const upload = multer({
  dest: '/tmp/uploads/',
  limits: {
    fileSize: 10 * 1024 * 1024, // 10 MB — enforced by busboy during streaming
    // When this limit is hit, busboy fires a LIMIT_FILE_SIZE error
    // and the request is aborted — only the first 10 MB are written
    fields: 5,
    files: 1,
  },
  fileFilter: (req, file, cb) => {
    // MIME type check during header parsing — before ANY data is written
    const allowed = new Set(['application/zip', 'application/x-zip-compressed']);
    if (!allowed.has(file.mimetype)) {
      return cb(new Error('Only .zip files allowed'), false);
    }
    cb(null, true);
  },
});

// Handle the LIMIT_FILE_SIZE error from multer
app.post('/upload/skill-zip', (req, res, next) => {
  upload.single('file')(req, res, (err) => {
    if (err?.code === 'LIMIT_FILE_SIZE') {
      return res.status(413).json({ error: 'File too large (max 10 MB)' });
    }
    if (err) return res.status(400).json({ error: err.message });
    next();
  });
}, (req, res) => {
  // File is on disk and within the size limit — process it
  processUploadedZip(req.file);
  res.json({ ok: true });
});
HIGH
SA-SKL-MULTIPART4-003 — Application-level file size checks in the route handler run after multer has already written the full file to temp disk — concurrent 2 GB uploads from an attacker exhaust the disk partition before any rejection executes; fix by setting limits.fileSize in the multer options object (enforced by busboy during streaming, aborting before the full file is written) rather than relying on fs.stat in the handler. Detection: SkillAudit flags multer or busboy upload handlers that check file size in the route handler body (req.file.size, fs.stat) without also having limits.fileSize set in the multer/busboy options.

MULTIPART4-004 — Concurrent multipart chunk reassembly race via shared upload ID

MCP skills that accept large file uploads split across multiple chunks implement a server-side reassembly mechanism: each chunk is submitted with an upload ID and a chunk index, stored temporarily, and reassembled when the final chunk arrives. If the upload ID is user-controlled (passed in the request body or query string rather than generated server-side), two concurrent parallel uploads from the same attacker — both claiming the same upload ID — write to the same set of chunk files. Chunk A from upload 1 and chunk A from upload 2 both write to /tmp/uploads/ABC123/chunk-0. The second write overwrites the first. When reassembly runs, the resulting file is a mix of bytes from both uploads — either corrupted, or deliberately crafted by the attacker to pass validation checks using data from one upload while the executable payload comes from the other. The fix is to generate the upload ID server-side using a cryptographically random UUID and return it to the client, never trusting the client-supplied ID.

// VULNERABLE — MULTIPART4-004
// chunk-upload.js — upload ID comes from client — concurrent uploads corrupt each other
import { mkdirSync, writeFileSync } from 'fs';
import { join } from 'path';

app.post('/upload/chunk', express.raw({ type: '*/*', limit: '1mb' }), async (req, res) => {
  const uploadId = req.headers['x-upload-id'];   // DANGEROUS: client controls this
  const chunkIndex = Number(req.headers['x-chunk-index']);

  // Two concurrent requests with the same x-upload-id both write here:
  const chunkDir = join('/tmp/uploads', uploadId);
  mkdirSync(chunkDir, { recursive: true });
  const chunkPath = join(chunkDir, `chunk-${chunkIndex}`);
  writeFileSync(chunkPath, req.body); // Second write overwrites first — corruption

  res.json({ ok: true });
});

// Attack: attacker sends upload 1 (legitimate) and upload 2 (payload) with the same uploadId
// Chunk 0 of upload 2 overwrites chunk 0 of upload 1 — reassembled file is hybrid
// FIXED — MULTIPART4-004: server-generated UUID upload ID returned to client on session init
import { randomUUID } from 'crypto';
import { mkdirSync, writeFileSync, existsSync } from 'fs';
import { join } from 'path';

// Step 1: client calls this to get a server-generated upload ID
app.post('/upload/init', requireAuth, (req, res) => {
  const uploadId = randomUUID(); // Cryptographically random — unpredictable, unique
  const { totalChunks, filename } = req.body;

  // Store upload session in Redis with the server-generated ID
  redis.setEx(`upload:${uploadId}`, 3600, JSON.stringify({
    userId: req.user.id,
    totalChunks,
    filename: sanitizeFilename(filename),
    receivedChunks: [],
  }));
  res.json({ uploadId }); // Client uses THIS id — cannot substitute another
});

// Step 2: client submits chunks using the server-issued uploadId
app.post('/upload/chunk', requireAuth, express.raw({ type: '*/*', limit: '1mb' }),
  async (req, res) => {
    const uploadId = req.headers['x-upload-id'];
    const chunkIndex = Number(req.headers['x-chunk-index']);

    // Verify this uploadId belongs to the authenticated user (prevents ID guessing)
    const sessionRaw = await redis.get(`upload:${uploadId}`);
    if (!sessionRaw) return res.status(404).json({ error: 'Upload session not found' });
    const session = JSON.parse(sessionRaw);
    if (session.userId !== req.user.id) return res.status(403).json({ error: 'Forbidden' });

    // Per-upload directory derived from server-generated UUID — unique per session
    const chunkDir = join('/tmp/uploads', uploadId);
    mkdirSync(chunkDir, { recursive: true });
    writeFileSync(join(chunkDir, `chunk-${chunkIndex}`), req.body);

    // Update received chunks list atomically
    session.receivedChunks.push(chunkIndex);
    await redis.setEx(`upload:${uploadId}`, 3600, JSON.stringify(session));
    res.json({ ok: true });
  }
);
HIGH
SA-SKL-MULTIPART4-004 — Chunked upload implementations that accept a client-supplied upload ID as the chunk directory key allow an attacker to send two concurrent uploads with the same ID — the second upload's chunks overwrite the first's, producing a hybrid file that may pass validation using bytes from one upload while delivering a payload from the other; fix by generating the upload ID server-side with randomUUID() during an upload-init endpoint, storing it with the authenticated user's ID in Redis, and rejecting any chunk request where the upload ID does not match the requesting user. Detection: SkillAudit flags chunked upload handlers that use req.headers['x-upload-id'], req.body.uploadId, or req.query.uploadId as a filesystem path component without verifying the ID was generated and issued by the server.

Detection summary

ID Severity Pattern Fix
MULTIPART4-001 HIGH No limits.fields in multer/busboy — 100k fields exhaust Node.js heap Set limits.fields: 20 (or appropriate max) in multer/busboy options
MULTIPART4-002 HIGH Null byte in filename passes extension check; truncates to .sh at OS level Strip null bytes and control chars from filename before extension validation
MULTIPART4-003 HIGH App-level size check after full file write — concurrent 2 GB uploads exhaust disk limits.fileSize in multer options (enforced during streaming)
MULTIPART4-004 HIGH Client-supplied upload ID as chunk directory key — concurrent uploads overwrite chunks Server-generated UUID upload ID; bind to authenticated user in Redis

Related patterns: SA-SKL-MULTIPART3 covers earlier multipart patterns including Content-Disposition header injection and content-type mismatch. SA-SKL-UPLOAD3 covers MIME confusion and polyglot file attacks at the MIME detection layer — the validation step that MULTIPART4-003 must run after streaming. SA-SKL-TIMEOUT covers unbounded body size on streaming endpoints — the same resource exhaustion class as MULTIPART4-001 and MULTIPART4-003 but on JSON/text request bodies.