Refactor coderd/chats.go to use 404 errors instead of 403/400 for resource lookups
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 70/100
Piste de recherche
Commencez dans coderd/chats.go au niveau de chatCostSummary, chatStream et validateCreateChatWorkspaceSelection, puis comparez leur traitement avec le modèle de référence dans coderd/workspaces.go. Modifiez uniquement les erreurs de recherche et d’autorisation propres aux ressources afin qu’elles utilisent des réponses 404, tout en conservant les réponses 403 pour les endpoints d’administration et de configuration du déploiement indiqués. C’est terminé lorsque les cas de ressources spécifiés renvoient 404 sans modifier le comportement d’administration documenté.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Problem
coderd/chats.go uses httpapi.Forbidden() (403) and http.StatusBadRequest (400) in several places where a 404 Not Found should be returned instead. This leaks information about resource existence and authorization state, and is inconsistent with the rest of the codebase which uses httpapi.ResourceNotFound() for these cases.
Scope
Note: Not all
httpapi.Forbidden()calls need to change. Documented admin API paths (e.g. deployment config / provider / model config CRUD endpoints) are fine returning 403 Forbidden — those endpoints don't expose whether a specific user-owned resource exists. The refactor should focus on handlers that gate access to specific resources (chats, workspaces, etc.) where returning 403 or 400 leaks that the resource exists.
What Should Change
1. Authorization checks on user-owned resources returning 403 instead of 404
These handlers check authorization against a specific resource and should return 404 to avoid leaking existence:
chatCostSummary(line ~392): Returnshttpapi.Forbidden(rw)when user lacksActionReadon a specific user'sResourceChat— should be 404chatStream→ workspace authorization (line ~777): Returnshttpapi.Forbidden(rw)when user lacksActionApplicationConnectorActionSSHon a specific workspace — should be 404
2. Resource lookup failures returning 400 Bad Request instead of 404
validateCreateChatWorkspaceSelection(line ~1917): Returnshttp.StatusBadRequestwith message"Workspace not found or you do not have access to this resource"when workspace is not found viahttpapi.Is404Error(err)— should be 404validateCreateChatWorkspaceSelection(line ~1932): Returnshttp.StatusBadRequestwith the same message whenapi.Authorize(r, policy.ActionSSH, workspace)fails — should be 404chatStream(line ~770): Returnshttp.StatusBadRequestwith"Chat workspace not found."whenGetWorkspaceByIDfails — should be 404
3. Forbidden calls that are fine as-is (no change needed)
These are documented admin API endpoints where 403 is appropriate — the endpoint path itself is known, and no user-specific resource existence is leaked:
chatCostUsers(line ~453):ActionReadonResourceChat(admin endpoint)chatUploadFile(line ~2149):ActionCreateonResourceChat(general permission, not resource-specific)chatProvidersList(line ~2663):ActionReadonResourceDeploymentConfigcreateChatProvider(line ~2773):ActionUpdateonResourceDeploymentConfigupdateChatProvider(line ~2851):ActionUpdateonResourceDeploymentConfigdeleteChatProvider(line ~2937):ActionUpdateonResourceDeploymentConfigcreateChatModelConfig(line ~3005):ActionUpdateonResourceDeploymentConfigupdateChatModelConfig(line ~3152):ActionUpdateonResourceDeploymentConfigdeleteChatModelConfig(line ~3322):ActionUpdateonResourceDeploymentConfig
Expected Behavior
- Resource lookups that fail (including authz rejections against specific resources) should return
404 Not Foundusinghttpapi.ResourceNotFound(rw), consistent with the pattern used throughout the rest of the codebase (e.g.,coderd/workspaces.go) - This prevents leaking information about whether a resource exists or whether the user lacks permissions
- Admin/deployment-config authorization checks should remain 403 Forbidden
Reference Pattern
The codebase already has the correct pattern in many places in chats.go itself (e.g., provider/model config CRUD using httpapi.Is404Error → httpapi.ResourceNotFound), as well as in other handlers like coderd/workspaces.go.
Created on behalf of @ThomasK33
- Langage dominant
- Go
- Étoiles
- 16.6k
- Forks
- 1.6k
- Merge moyen
- 1 j 23 h
- PR mergées (30 j)
- 543
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de coder/coder
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
-
feat(site): suppress the web terminal context menu when the application has enabled mouse tracking Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
bug frontend
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
-
bug site
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Toutes les issues de coder/coder
Issues similaires
-
agentic-workflows
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
agentic-workflows
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
microsoft/agent-framework-go#1179 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
[Bug]: OLLAMA_KEEP_ALIVE="5m" / "24h" crashes Ollama embedding and vision models with ValueError Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
infiniflow/ragflow#20223 · 1 réaction ·
-
bug needs triage pkg/translator/faro
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
open-telemetry/opentelemetry-collector-contrib#51484 · 1 commentaire ·