Skip to content
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

feat(appcheck): Added replay protection feature to App Check verifyToken() API #2148

Merged
merged 9 commits into from May 2, 2023

Conversation

lahirumaramba
Copy link
Member

@lahirumaramba lahirumaramba commented Apr 12, 2023

RELEASE NOTE: Added replay protection feature to App Check verifyToken() API.

return true;
})
.catch((err) => {
throw this.toFirebaseError(err);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Just for informational purposes, no action needed.) Right now the backend has two main error conditions (in this order of priority):

  1. If the token is invalid (expired, invalid signature, wrong audience, etc.), an HTTP 403 Forbidden will be returned.
  2. If the token had a provider of safety_net, an HTTP 400 Bad Request will be returned. (Maybe we could even detect this early and avoid the network call?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point! Since we check the validity of the token prior to making the call to BE, 1) should be addressed already. How do we check 2)?, is it a custom claim encoded in the JWT?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For (2), yes, it is actually a private claim named provider in the JWT, but now that I think about this more, I think a more robust method for detecting whether the token supports Replay Protection is to see whether its jti claim is populated with a nonempty string rather than checking the provider claim against a hardcoded list of allowed providers.

src/app-check/app-check-api.ts Outdated Show resolved Hide resolved
src/app-check/app-check-api.ts Outdated Show resolved Hide resolved
src/app-check/app-check.ts Show resolved Hide resolved
@lahirumaramba lahirumaramba force-pushed the lm-fac-1use branch 3 times, most recently from c51e981 to 913d149 Compare April 14, 2023 21:07
@@ -41,6 +41,27 @@ export interface AppCheckTokenOptions {
ttlMillis?: number;
}

/**
* Interface representing options for {@link AppCheck.verifyToken} method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Interface representing options for {@link AppCheck.verifyToken} method.
* Interface representing options for the {@link AppCheck.verifyToken} method.

Comment on lines 49 to 52
* To use the replay protection feature, set this to true to mark the token as consumed.
* Tokens that are found to be already consumed will be marked as such in the response.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* To use the replay protection feature, set this to true to mark the token as consumed.
* Tokens that are found to be already consumed will be marked as such in the response.
* To use the replay protection feature, set this to true. The {@link AppCheck.verifyToken}
* method will mark the token as consumed after verifying it.
*
* Tokens that are found to be already consumed will be marked as such in the response.

src/app-check/app-check.ts Show resolved Hide resolved
@lahirumaramba lahirumaramba changed the title feat(appcheck): App check improvements feat(appcheck): Added replay protection feature to App Check verifyToken() API Apr 19, 2023
@lahirumaramba lahirumaramba merged commit a43df9e into master May 2, 2023
5 checks passed
@lahirumaramba lahirumaramba deleted the lm-fac-1use branch May 2, 2023 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants