Skip to content

Commit d8c2a61

Browse files
Potential fix for code scanning alert no. 5: Type confusion through parameter tampering
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent b6af0c5 commit d8c2a61

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

samples/hash-server/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ app.use(express.json());
180180
// Classification endpoint
181181
app.post('/', upload.array('image'), async (req: Request, res: Response) => {
182182
try {
183+
// Defensive: Multer should always provide an array here, but check to prevent type confusion.
184+
if (!Array.isArray(req.files)) {
185+
return res.status(400).json({
186+
error: 'Invalid files payload',
187+
message: 'The "image" field must be an array of files'
188+
});
189+
}
183190
const files = req.files as Express.Multer.File[];
184191

185192
if (!files || files.length === 0) {

0 commit comments

Comments
 (0)