Skip to content

Commit

Permalink
catch expiration bug (#677)
Browse files Browse the repository at this point in the history
* fix: add logs and catch error

* ci.yaml: remove unnecessary steps in the CI workflow

service.ts: remove unnecessary try-catch block for checking key expiration

* fix(service.ts): fix expiration check for keys with serialized date strings in zone cache

* fix(service.ts): fix typo in comment, change "the" to "them"
  • Loading branch information
chronark authored Dec 12, 2023
1 parent 3ba0fc3 commit 709df5c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apps/api/src/pkg/keys/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ export class KeyService {
/**
* Expiration
*/
if (data.key.expires && data.key.expires.getTime() < Date.now()) {
return result.success({ valid: false, code: "NOT_FOUND" });
if (data.key.expires) {
// The zone cache can not deserialize dates and returns them as string, so we need to do it manually
const expires = new Date(data.key.expires).getTime();
if (expires < Date.now()) {
return result.success({ valid: false, code: "NOT_FOUND" });
}
}

if (data.api.ipWhitelist) {
Expand All @@ -178,7 +182,6 @@ export class KeyService {
/**
* Ratelimiting
*/

const [pass, ratelimit] = await this.ratelimit(c, data.key);
if (!pass) {
return result.success({
Expand Down

0 comments on commit 709df5c

Please sign in to comment.