Skip to content

Commit 97ece1e

Browse files
Require exp field in license validation
1 parent 06882ec commit 97ece1e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

react_on_rails_pro/lib/react_on_rails_pro/license_validator.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ def validate_license
3636
license = load_and_decode_license
3737
return false unless license
3838

39-
# Check expiry if present
40-
if license["exp"] && Time.now.to_i > license["exp"]
39+
# Check that exp field exists
40+
unless license["exp"]
41+
@validation_error = "License is missing required expiration field"
42+
handle_invalid_license(development_mode, @validation_error)
43+
return development_mode
44+
end
45+
46+
# Check expiry
47+
if Time.now.to_i > license["exp"]
4148
@validation_error = "License has expired"
4249
handle_invalid_license(development_mode, @validation_error)
4350
return development_mode
@@ -63,6 +70,9 @@ def load_and_decode_license
6370
license_string,
6471
public_key,
6572
true,
73+
# NOTE: Never remove the 'algorithm' parameter from JWT.decode to prevent algorithm bypassing vulnerabilities.
74+
# Ensure to hardcode the expected algorithm.
75+
# See: https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/
6676
algorithm: "RS256"
6777
).first
6878
end

react_on_rails_pro/packages/node-renderer/src/shared/licenseValidator.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PUBLIC_KEY } from './licensePublicKey';
66
interface LicenseData {
77
sub?: string;
88
iat?: number;
9-
exp?: number;
9+
exp: number; // Required: expiration timestamp
1010
[key: string]: any;
1111
}
1212

@@ -60,8 +60,15 @@ class LicenseValidator {
6060
return false;
6161
}
6262

63-
// Check expiry if present
64-
if (license.exp && Date.now() / 1000 > license.exp) {
63+
// Check that exp field exists
64+
if (!license.exp) {
65+
this.validationError = 'License is missing required expiration field';
66+
this.handleInvalidLicense(isDevelopment, this.validationError);
67+
return isDevelopment;
68+
}
69+
70+
// Check expiry
71+
if (Date.now() / 1000 > license.exp) {
6572
this.validationError = 'License has expired';
6673
this.handleInvalidLicense(isDevelopment, this.validationError);
6774
return isDevelopment;

0 commit comments

Comments
 (0)