Skip to content

Commit b966568

Browse files
author
Hyunje Jun
authored
Merge pull request #26 from musou1500/fix-middleware-signature-validation
fix signature validation
2 parents 28e36f7 + e3ee0bf commit b966568

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/exceptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class SignatureValidationFailed extends Error {
22
constructor(
33
message: string,
4-
public signature: string,
4+
public signature?: string,
55
) {
66
super(message);
77
}

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"));
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)