kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Bug: Unhandled empty string and incomplete hyphen replacement in RegisterFacilityModal token validation

Open eshanthh opened this issue 6 months ago • 1 comments

❌ 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

  1. The token should have all hyphens stripped globally, not just the first one.
  2. The stripped token should be trimmed of whitespace.
  3. If the resulting token is empty, the function should return early (synchronously) and set this.invalid = true to display an error and avoid making an unnecessary API request.
  4. The method should safely handle cases where this.token is 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

  1. Navigate to packages/kolibri-common/components/syncComponentSet/RegisterFacilityModal.vue.
  2. Inspect the validateToken function around line 87.
  3. Observe the // TODO synchronously handle empty strings comment.
  4. 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.

eshanthh avatar May 20 '26 07:05 eshanthh

/assign

eshanthh avatar May 20 '26 07:05 eshanthh