-
Notifications
You must be signed in to change notification settings - Fork 947
Add option to skip signature verification #1635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
fce264e
b9c3430
4470df6
7e4a768
464a9d8
5a25f88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2025 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.bot.parser; | ||
|
||
public class FixedSkipSignatureVerificationSupplier implements SkipSignatureVerificationSupplier { | ||
private final boolean fixedValue; | ||
|
||
public FixedSkipSignatureVerificationSupplier(boolean fixedValue) { | ||
this.fixedValue = fixedValue; | ||
} | ||
|
||
public static FixedSkipSignatureVerificationSupplier of(boolean fixedValue) { | ||
return new FixedSkipSignatureVerificationSupplier(fixedValue); | ||
} | ||
|
||
@Override | ||
public boolean getAsBoolean() { | ||
return fixedValue; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2025 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.bot.parser; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
/** | ||
* Special {@link BooleanSupplier} for Skip Signature Verification. | ||
* | ||
* <p>You can implement it to return whether to skip signature verification. | ||
* | ||
* <p>If true is returned, webhook signature verification is skipped. | ||
* This may be helpful when you update the channel secret and want to skip the verification temporarily. | ||
*/ | ||
@FunctionalInterface | ||
public interface SkipSignatureVerificationSupplier extends BooleanSupplier { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ public class WebhookParser { | |
|
||
private final ObjectMapper objectMapper = ModelObjectMapper.createNewObjectMapper(); | ||
private final SignatureValidator signatureValidator; | ||
private final SkipSignatureVerificationSupplier skipSignatureVerificationSupplier; | ||
|
||
/** | ||
* Creates a new instance. | ||
|
@@ -42,6 +43,19 @@ public class WebhookParser { | |
*/ | ||
public WebhookParser(SignatureValidator signatureValidator) { | ||
this.signatureValidator = requireNonNull(signatureValidator); | ||
this.skipSignatureVerificationSupplier = FixedSkipSignatureVerificationSupplier.of(false); | ||
} | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param signatureValidator LINE messaging API's signature validator | ||
* @param skipSignatureVerificationSupplier Supplier to determine whether to skip signature verification | ||
*/ | ||
public WebhookParser(SignatureValidator signatureValidator, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you update javadoc(comment) to explain when we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you create another constructor that doesn't break the build, and keep current constructor? Alternatively, you could set a non-skipping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In cases other than temporary migration for channel secret, it should often be specified as Having it set to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean to say this?
I have made the change to set the default to false. Please review it. b9c3430 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops, yes |
||
SkipSignatureVerificationSupplier skipSignatureVerificationSupplier) { | ||
this.signatureValidator = requireNonNull(signatureValidator); | ||
this.skipSignatureVerificationSupplier = requireNonNull(skipSignatureVerificationSupplier); | ||
} | ||
|
||
/** | ||
|
@@ -62,7 +76,8 @@ public CallbackRequest handle(String signature, byte[] payload) throws IOExcepti | |
log.debug("got: {}", new String(payload, StandardCharsets.UTF_8)); | ||
} | ||
|
||
if (!signatureValidator.validateSignature(payload, signature)) { | ||
if (!skipSignatureVerificationSupplier.getAsBoolean() | ||
&& !signatureValidator.validateSignature(payload, signature)) { | ||
throw new WebhookParseException("Invalid API signature"); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(add comment)
+ if
true
is passed, webhook signature verification is skipped. This may be helpful when you update channel secret and you want to skip the verification temporarily.