Repository navigation
fix: chat authentication version detection #8290
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ export interface AuthProfile<Meta = Record<string, never>> { | |
| logo: string | ||
| custom_theme?: { theme_color?: string; header_font_color?: string } | null | ||
| edition?: string | ||
| /** 当前 license 是否有效;专业版、企业版据此判断授权相关能力。 */ | ||
| license_is_valid?: boolean | ||
| meta: Meta | ||
| } | ||
|
|
||
|
Contributor
Author
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. Verdict: The added field is syntactically valid and backward-compatible. No performance concern. The main risks are semantic/security-related. Potential issues
Suggested comment /** Whether the current license is valid. Missing/undefined must be treated as invalid. */
license_is_valid?: booleanTests to add
Overall: no syntax issue; just clarify optionality, default behavior, and server-side enforcement. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,8 +76,10 @@ export const useChatAuthStore = defineStore('chat-auth', { | |
| if (isPortalScope(state.scope)) return undefined | ||
| return (state.authProfile?.meta as ApplicationAuthProfileMeta | undefined)?.application_id | ||
| }, | ||
| /** 社区版 */ | ||
| isCE: (state) => state.authProfile?.edition === 'CE', | ||
| /** 专业版 */ | ||
| isPE: (state) => state.authProfile?.edition === 'PE' && Boolean(state.authProfile.license_is_valid), | ||
| /** 企业版 */ | ||
| isEE: (state) => state.authProfile?.edition === 'EE' && Boolean(state.authProfile.license_is_valid), | ||
| }, | ||
|
|
||
| actions: { | ||
|
Contributor
Author
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. No syntax error in the diff, but there are a few important issues and improvements. Potential issues
Suggested refactorconst hasValidLicense = (state) =>
state.authProfile?.license_is_valid === true
export const useChatAuthStore = defineStore('chat-auth', {
// ...
getters: {
isCE: (state) => state.authProfile?.edition === 'CE',
isPE: (state) =>
state.authProfile?.edition === 'PE' && hasValidLicense(state),
isEE: (state) =>
state.authProfile?.edition === 'EE' && hasValidLicense(state),
},
})Add the correct state type to |
||
|
|
||
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.
The added helper and response field are reasonable, but there are a few robustness and performance concerns.
Potential issues
The fallback only handles missing/falsy values
This works if the lookup returns
None, but it does not handle:get_model()raising an exceptionIf the lookup returns a model class instead of a zero-argument validator function,
validator()may create a model instance, andbool(instance)may beTrueeven when the license is invalid. Validate that the result is callable.No exception handling
If the license validator raises, the entire profile endpoint will fail with a 500. A licensing check should usually fail closed but not crash the profile response:
Repeated evaluation / performance
_is_license_valid()may hit the database or a license service. It is called in several response branches. Even if only one branch runs per request, computing it once and reusing the value is cleaner. If the profile endpoint is high-traffic, consider a short-lived cache with explicit invalidation when the license changes.Boolean contract is ambiguous
bool(validator())treats"False"asTrue. Make sure the registeredlicense_is_validcallable is contractually required to return a real boolean, or explicitly check:Use this only if the validator is guaranteed to return
True/False.Silent failure may hide misconfiguration
Returning
Falsewhen the validator is missing is probably acceptable, but log a warning so missing plugin/configuration issues are visible.Security / authorization
license_is_validin the profile response should be treated as UI metadata only. Do not rely on the client-side flag to enable licensed functionality; enforce license checks server-side. Also confirm that exposing license status in anonymous/portal profiles is intended.Check all profile response paths
Ensure every profile response shape includes
license_is_valid. If some branches omit it, the frontend may see inconsistent data. Also confirmeditionandlicense_is_validcannot contradict each other.Existing context line looks syntactically invalid
This line in the diff context looks incomplete:
If that is literal code, it will not parse. It may just be truncated diff context, but it is worth verifying.
Suggested implementation
Then compute once per profile request:
If
_is_license_valid()is expensive and the license changes rarely, add a short TTL cache or invalidate the cache when the license is updated. Avoid an indefinitely cached boolean unless you have reliable invalidation.Also add tests for: