Skip to content

Commit 9e5e9d2

Browse files
committed
fix signature validation
1 parent 28e36f7 commit 9e5e9d2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function middleware(config: Line.Config & Line.MiddlewareConfig):
2222
const signature = req.headers["x-line-signature"] as string;
2323

2424
if (!signature) {
25-
next();
25+
next(new SignatureValidationFailed("no signature", signature));
2626
return;
2727
}
2828

test/middleware.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,18 @@ describe("middleware", () => {
7272
equal(err.statusCode, 400);
7373
});
7474
});
75+
76+
it("fails on empty signature", () => {
77+
return post(`${TEST_URL}/webhook`, {}, { events: [webhook] })
78+
.then((res: any) => {
79+
throw new Error();
80+
})
81+
.catch((err: any) => {
82+
if (err instanceof HTTPError) {
83+
equal(err.statusCode, 401);
84+
} else {
85+
throw err;
86+
}
87+
});
88+
});
7589
});

0 commit comments

Comments
 (0)