Skip to content

Commit 6056c34

Browse files
committed
fix(security): validate req.body is a Buffer before parsing pkt-lines
1 parent 53a3f3a commit 6056c34

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/proxy/processors/pktLineParser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import { PACKET_SIZE } from './constants';
2323
* @return {[string[], number]} An array containing the parsed lines and the offset after the last parsed line/flush packet.
2424
*/
2525
export const parsePacketLines = (buffer: Buffer): [string[], number] => {
26+
if (!Buffer.isBuffer(buffer)) {
27+
throw new Error('parsePacketLines expected a Buffer');
28+
}
2629
const lines: string[] = [];
2730
let offset = 0;
2831

src/proxy/processors/push-action/parsePush.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ async function exec(req: Request, action: Action): Promise<Action> {
5757
if (!req.body || req.body.length === 0) {
5858
throw new Error('No body found in request');
5959
}
60+
if (!Buffer.isBuffer(req.body)) {
61+
throw new Error('Request body must be a Buffer');
62+
}
6063
const [packetLines, packDataOffset] = parsePacketLines(req.body);
6164
const refUpdates = packetLines.filter((line) => line.includes(BRANCH_PREFIX));
6265

0 commit comments

Comments
 (0)