-
Notifications
You must be signed in to change notification settings - Fork 51
fix: wildcard MIME types validation #2203
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
base: dev
Are you sure you want to change the base?
Conversation
❌ Deploy Preview for kleros-v2-testnet failed. Why did it fail? →
|
✅ Deploy Preview for kleros-v2-neo ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
❌ Deploy Preview for kleros-v2-testnet-devtools failed. Why did it fail? →
|
WalkthroughModified MIME type validation in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx (1)
283-293: Wildcard MIME validation works forimage/*; consider a clearer prefix derivation and*/*behaviorThe
.somelogic correctly handles patterns likeimage/*and exact matches, so it should unblock the Curate V2image/*use case. Two small nits you may want to consider:
allowedType.replace("/*", "/")is a bit opaque and will replace the first/*anywhere in the string. Using a simple slice is clearer and safer for future patterns:- const isValidMimeType = restrictions.restriction.allowedMimeTypes.some((allowedType) => { - if (allowedType.endsWith("/*")) { - const prefix = allowedType.replace("/*", "/"); - return file.type.startsWith(prefix); - } - return allowedType === file.type; - }); + const isValidMimeType = restrictions.restriction.allowedMimeTypes.some((allowedType) => { + if (allowedType.endsWith("/*")) { + // e.g. "image/*" -> "image/" + const prefix = allowedType.slice(0, -1); // drop only the '*' + return file.type.startsWith(prefix); + } + return allowedType === file.type; + });
- If you ever plan to support
*/*as a true “any MIME type” wildcard, the current logic won’t match anything (prefix becomes*/). You might want to either explicitly special‑case*/*now or document that onlytype/*wildcards are supported.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx(1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1727
File: web/src/context/AtlasProvider.tsx:159-171
Timestamp: 2024-10-29T06:46:13.522Z
Learning: Both `SubmitEvidenceModal.tsx` and `Policy/index.tsx` use the `uploadFile` function from `AtlasProvider`, which includes the `fetchWithAuthErrorHandling` error handling utility.
📚 Learning: 2024-10-15T16:18:32.543Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1687
File: web/src/context/AtlasProvider.tsx:225-244
Timestamp: 2024-10-15T16:18:32.543Z
Learning: In `web/src/context/AtlasProvider.tsx`, the `atlasUri` variable comes from environment variables and does not change, so it does not need to be included in dependency arrays.
Applied to files:
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx
📚 Learning: 2024-11-21T06:14:26.307Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1755
File: kleros-app/src/lib/atlas/utils/addUser.ts:18-37
Timestamp: 2024-11-21T06:14:26.307Z
Learning: In the `kleros-app/src/lib/atlas/utils/addUser.ts` file, email format validation is performed by the server in the `addUser` function. The library does not include client-side email validation, and it's the responsibility of the library consumers to perform any pre-checks if desired.
Applied to files:
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx
📚 Learning: 2024-10-29T06:46:13.522Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1727
File: web/src/context/AtlasProvider.tsx:159-171
Timestamp: 2024-10-29T06:46:13.522Z
Learning: Both `SubmitEvidenceModal.tsx` and `Policy/index.tsx` use the `uploadFile` function from `AtlasProvider`, which includes the `fetchWithAuthErrorHandling` error handling utility.
Applied to files:
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx
📚 Learning: 2024-11-21T05:47:08.973Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1755
File: kleros-app/src/lib/atlas/providers/AtlasProvider.tsx:130-144
Timestamp: 2024-11-21T05:47:08.973Z
Learning: In `kleros-app/src/lib/atlas/providers/AtlasProvider.tsx`, it is acceptable to pass `queryClient` as a positional parameter to the `useQuery` hook.
Applied to files:
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx
📚 Learning: 2024-10-28T12:20:19.884Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1727
File: web/src/utils/atlas/updateEmail.ts:34-37
Timestamp: 2024-10-28T12:20:19.884Z
Learning: In `web/src/utils/atlas/updateEmail.ts`, the error coming from the `GraphQLError` array already has the necessary structure, so additional specificity in error handling is unnecessary.
Applied to files:
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx
📚 Learning: 2024-10-28T12:21:21.532Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1727
File: web/src/utils/atlas/uploadToIpfs.ts:45-0
Timestamp: 2024-10-28T12:21:21.532Z
Learning: In the `uploadToIpfs` function in `web/src/utils/atlas/uploadToIpfs.ts`, the API error responses always include a defined `error.message`, so additional handling for undefined messages is unnecessary.
Applied to files:
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx
📚 Learning: 2024-10-28T12:20:36.536Z
Learnt from: Harman-singh-waraich
Repo: kleros/kleros-v2 PR: 1727
File: web/src/utils/atlas/updateEmail.ts:32-33
Timestamp: 2024-10-28T12:20:36.536Z
Learning: In the 'kleros-v2' project, it's acceptable to log raw error objects in production code, including in the `updateEmail` function within `web/src/utils/atlas/updateEmail.ts`.
Applied to files:
kleros-app/src/lib/atlas/providers/AtlasProvider.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
- GitHub Check: Redirect rules - kleros-v2-neo
- GitHub Check: Redirect rules - kleros-v2-testnet-devtools
- GitHub Check: Header rules - kleros-v2-neo
- GitHub Check: Redirect rules - kleros-v2-testnet
- GitHub Check: Redirect rules - kleros-v2-testnet
- GitHub Check: Header rules - kleros-v2-testnet-devtools
- GitHub Check: Header rules - kleros-v2-testnet
- GitHub Check: Header rules - kleros-v2-testnet
- GitHub Check: Pages changed - kleros-v2-testnet-devtools
- GitHub Check: Pages changed - kleros-v2-neo
- GitHub Check: Pages changed - kleros-v2-testnet
- GitHub Check: Pages changed - kleros-v2-testnet
- GitHub Check: Analyze (javascript)
- GitHub Check: hardhat-tests



Resolves #2202.
PR-Codex overview
This PR modifies the file type validation logic in the
AtlasProvider.tsxfile to allow for more flexible MIME type checks, accommodating wildcard patterns.Detailed summary
allowedMimeTypeswith a more complex validation usingsome.image/*).Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.