Bug: Unhandled empty string and incomplete hyphen replacement in RegisterFacilityModal token validation
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Target branch: develop
Observed behavior
In the RegisterFacilityModal.vue file (located at packages/kolibri-common/components/syncComponentSet/RegisterFacilityModal.vue), there is a TODO comment indicating a need to synchronously handle empty strings for the project token before dispatching a validation request to the backend.
Furthermore, the current token stripping logic uses const strippedToken = this.token.replace('-', '');, which only replaces the first occurrence of a hyphen, rather than all occurrences (which would require a global regex like /-/g).
If the user somehow passes a token consisting entirely of hyphens or whitespace, the logic will send an empty string to PortalResource.validateToken(strippedToken), causing an unnecessary API request and potentially unhandled edge cases. If this.token is undefined or null, .replace will throw a runtime error.
Errors and logs
No specific logs, but a runtime error would occur in the browser console if this.token is ever null/undefined:
Expected behavior
- The token should have all hyphens stripped globally, not just the first one.
- The stripped token should be trimmed of whitespace.
- If the resulting token is empty, the function should return early (synchronously) and set
this.invalid = trueto display an error and avoid making an unnecessary API request. - The method should safely handle cases where
this.tokenis falsy to prevent runtime exceptions.
User-facing consequences
Admins attempting to register a facility with a malformed token with multiple hyphens might experience unexpected validation issues or errors. Passing invalid empty strings to the backend also creates unnecessary network traffic.
Steps to reproduce
- Navigate to
packages/kolibri-common/components/syncComponentSet/RegisterFacilityModal.vue. - Inspect the
validateTokenfunction around line 87. - Observe the
// TODO synchronously handle empty stringscomment. - Observe the
this.token.replace('-', '')logic that only replaces the first hyphen and fails to protect against falsy token values.
Context
- Application version: Develop
- Operating system: All
- Browser: All
AI usage
I used an AI coding assistant to explore the Kolibri codebase for open TODOs and good first issues. The assistant identified this specific frontend validation flaw and helped draft the technical explanation of why .replace('-', '') is insufficient and how empty strings were bypassing synchronous validation. I reviewed the code manually to verify the assistant's claims before filing this issue.
/assign