-
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: increment opened count when opening link from local server (#255) #381
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 3 commits
5bafcbe
05188c8
e36b367
2170bbd
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 |
|---|---|---|
|
|
@@ -328,6 +328,24 @@ open class LocalServerRepositoryImpl( | |
| ) | ||
| } | ||
| } | ||
|
|
||
| post("/api/links/increment-count") { | ||
| try { | ||
| val id = call.request.queryParameters["id"]?.toLongOrNull() | ||
| if (id != null) { | ||
| accountViewModel.incrementOpenedCount(id) | ||
| call.respond(HttpStatusCode.OK, SuccessResponse("Count incremented")) | ||
| } else { | ||
| call.respond(HttpStatusCode.BadRequest, ErrorResponse("Invalid link ID")) | ||
| } | ||
| } catch (e: Exception) { | ||
| Log.e("LocalServer", "Error incrementing count", e) | ||
| call.respond( | ||
| HttpStatusCode.InternalServerError, | ||
| ErrorResponse("Error incrementing count: ${e.message}"), | ||
| ) | ||
| } | ||
| } | ||
|
Comment on lines
+331
to
+348
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. 🧩 Analysis chain🏁 Script executed: # Find AccountViewModel file
fd -t f "AccountViewModel" --type kotlinRepository: yogeshpaliyal/Deepr Length of output: 236 🏁 Script executed: # Also try broader search in case naming differs
fd -t f -i "viewmodel" | grep -i accountRepository: yogeshpaliyal/Deepr Length of output: 134 🏁 Script executed: # Search for incrementOpenedCount in the entire codebase
rg -n "incrementOpenedCount" --type kotlinRepository: yogeshpaliyal/Deepr Length of output: 966 🏁 Script executed: # Check the AccountViewModel.incrementOpenedCount implementation
cat -n app/src/main/java/com/yogeshpaliyal/deepr/viewmodel/AccountViewModel.kt | sed -n '488,495p'Repository: yogeshpaliyal/Deepr Length of output: 363 🏁 Script executed: # Check the LinkRepositoryImpl.incrementOpenedCount implementation
cat -n app/src/main/java/com/yogeshpaliyal/deepr/data/LinkRepositoryImpl.kt | sed -n '219,235p'Repository: yogeshpaliyal/Deepr Length of output: 674 🏁 Script executed: # Also check the LinkRepository interface to understand the contract
cat -n app/src/main/java/com/yogeshpaliyal/deepr/data/LinkRepository.kt | sed -n '107,110p'Repository: yogeshpaliyal/Deepr Length of output: 182 🏁 Script executed: # Check how deeprQueries is used - likely SQLDelight generated code
rg -n "deeprQueries.incrementOpenedCount" --type-add 'kotlin:*.kt' -A 3 -B 3Repository: yogeshpaliyal/Deepr Length of output: 737 🏁 Script executed: # Check if there's any logging or observable that might show race condition
rg -n "insertDeeprOpenLog" --type-add 'kotlin:*.kt' -A 2 -B 2Repository: yogeshpaliyal/Deepr Length of output: 2068 Critical race condition: endpoint returns 200 OK before database operation completes. The issue is more severe than initial threading concern. The endpoint should either await the database operation (wrap in a suspend function and use a proper coroutine job) or use a blocking call if this is a local-only server. Secondary issue: No validation that the given 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Stored XSS via single-quote breakout in
onclickattribute.The
escapeHtml()function (Line 890) encodes<,>,&, and"but does not escape single quotes ('). Since the URL is interpolated inside single-quoted string delimiters in theonclickattribute:A malicious URL containing a single quote (e.g.,
https://x.com/');alert(document.cookie);//) will break out of the string literal and execute arbitrary JavaScript when the card is rendered. This is a stored XSS — any user who can add a link via the API can inject script that runs for every viewer.🔒 Proposed fix: use a data attribute and attach the handler programmatically, or escape single quotes
Option 1 (minimal fix): Escape single quotes in the interpolation context:
Option 2 (preferred): Use
data-*attributes and bind handlers viaaddEventListenerto avoid inline JS entirely. Store the id and url indata-link-idanddata-link-urlattributes (which are HTML-escaped byescapeHtml), then inDOMContentLoadeduse event delegation:This avoids any inline JS injection surface.
🤖 Prompt for AI Agents