BUG: evaluate-assessments Edge Function crashes on missing/malformed input and silently returns zero score on unmatched answers
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- typescript
Research direction
Start in supabase/functions/evaluate-assessments/index.ts by inspecting request parsing and the scoring loop. Run the two curl reproductions from the issue with missing input and unmatched IDs. Done means malformed requests return 400, and requests with no scorable questions return an error instead of a zero score.
Written by the indexing model from the issue text.
Description
Is there an existing issue for this?
- I have searched the existing issues
What happened?
📌 Issue Overview
The evaluate-assessments Edge Function has two related bugs:
-
No input validation — if the request body is empty, malformed JSON,
or missingpatient_id,assessment_id, orquestions, the function
crashes with an unhandledTypeError(e.g.questions.map is not a function) before reaching the try/catch, returning a 500 with no useful
error message. -
Silent zero score — if none of the submitted
question_id/answer_id
pairs match the assessment data (e.g. stale client data, wrong IDs), the
scoring loop silentlycontinues every iteration,totalScorestays 0,
and the patient is incorrectly told they are not autistic. There is no
warning that 0 out of N questions were scored.
🔍 Steps to Reproduce
Bug 1 — Null dereference:
curl -X POST https://.supabase.co/functions/v1/evaluate-assessments \
-H "Content-Type: application/json" \
-d '{}'
# Returns 500 Internal Server Error — questions is undefined, .map() crashes
Bug 2 — Silent zero score:
curl -X POST https://.supabase.co/functions/v1/evaluate-assessments \
-H "Content-Type: application/json" \
-d '{"patient_id":"...","assessment_id":"...","questions":[{"question_id":"wrong-id","answer_id":"wrong-id"}]}'
# Returns 200 with assessment_score: 0 and is_autistic: false — silently wrong
🎯 Expected Behavior
- Missing or malformed input should return a
400 Bad Requestwith a clear
error message before any processing begins. - If 0 out of N questions were successfully scored, the function should
return an error rather than a misleading result.
🚨 Actual Behavior
questions.map(...)throwsTypeError: Cannot read properties of undefined
whenquestionsis missing from the request body.- A patient who submits an assessment with entirely unmatched answers receives
assessment_score: 0andis_autistic: false— a clinically dangerous
false negative.
Root cause — supabase/functions/evaluate-assessments/index.ts:
// No validation — patient_id, assessment_id, questions can all be undefined
const { patient_id, assessment_id, questions } = await req.json();
// Crashes if questions is undefined
questions.map((q: AssessmentEvaluationQuestionDTO) => ({ ... }))
// Silent zero — no check that at least 1 question was scored
let totalScore = 0;
for(let i=0; i<answered_questions.questions.length; i++) {
...
if(!matched_question) { continue; } // silently skipped
if(!answer) { continue; } // silently skipped
}
// totalScore may still be 0 — no warning issued
📷 Screenshot
N/A
💡 Suggested Improvements
// 1. Validate input early
const body = await req.json().catch(() => null);
if (!body || !body.patient_id || !body.assessment_id || !Array.isArray(body.questions) || body.questions.length === 0) {
return new Response(JSON.stringify({ error: "Missing or invalid request body" }), { status: 400 });
}
// 2. Check that at least 1 question was scored
let scoredCount = 0;
for (...) {
...
totalScore += answer.score;
scoredCount++;
}
if (scoredCount === 0) {
return new Response(JSON.stringify({ error: "No questions could be scored — check question and answer IDs" }), { status: 422 });
}
Record
- I agree to follow this project's Code of Conduct
- I want to work on this issue
- Dominant language
- Dart
- Stars
- 30
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AOSSIE-Org/NeuroTrack
-
fix(therapist): Method marked @override does not override any inherited methodPossibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#198 ·
-
fix: Don't use BuildContext across async gaps (use_build_context_synchronously)Possibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#197 ·
-
fix(patient): Remove unused and duplicate imports across patient appPossibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AOSSIE-Org/NeuroTrack#195 ·
-
BUG: Therapy details save button has no loading guard, allowing duplicate submissions that inflate patient regression reportsPossibly taken @Varadraj75 claimed this 222 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#221 ·
-
BUG: Appointment booking ignores selected time slot, every appointment saved at midnight to SupabasePossibly taken @Varadraj75 claimed this 227 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
AOSSIE-Org/NeuroTrack#219 ·
All issues in AOSSIE-Org/NeuroTrack
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Anxcye/anx-reader#1024 ·
-
[cloud_functions]: Apple platforms ignore custom domains passed as regionPossibly taken @ragavendranbala-TSL claimed this today. OpenNeeds Attention platform: ios platform: macos plugin: functions type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/flutterfire#19015 · 2 comments ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RevenueCat/purchases-flutter#2048 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hajisensai/Fushi#4543 · 3 comments ·
Maintainers usually reply within 1 day
-
[video_player] _updatePosition sets isCompleted=true after 500ms when duration is Duration.zeroOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day