File Type Restriction Bypass via Rename
p5.js version
No response
What is your operating system?
None
Web browser and version
No response
Actual Behavior
User attempts to create a new file with a .obj extension (e.g., demo.obj) in the p5.js web editor The editor correctly blocks the creation and displays an error: "Invalid file type. Valid extensions are .js, .css, .json, .xml, .stl, .txt, .csv, .tsv, .mtl, .frag, and .vert." User creates a file with a valid extension (e.g., demo.js) — this succeeds User then renames demo.js to demo.obj The editor allows the rename without any validation, successfully creating a .obj file — bypassing the restriction entirely
Expected Behavior
When a user attempts to rename a file to an invalid extension (e.g., .obj), the editor should trigger the same validation as it does during file creation The rename action should be blocked and display the same error message: "Invalid file type. Valid extensions are .js, .css, .json, .xml, .stl, .txt, .csv, .tsv, .mtl, .frag, and .vert." The filename should revert back to its previous valid name File type restrictions should be consistently enforced across all entry points — both creation and rename — so there is no way to bypass the whitelist
Steps to reproduce
Steps:
Step 1: Open the p5.js web editor and log in to your account
Step 2: In the Sketch Files panel on the left side, click the "+" button to create a new file
Step 3: In the "Create File" dialog, type demo.obj and click "Add File"
✅ Confirm that the editor blocks this and shows the error: "Invalid file type. Valid extensions are .js, .css, .json, .xml, .stl, .txt, .csv, .tsv, .mtl, .frag, and .vert."
Step 4: Again click the "+" button and this time type demo.txt and click "Add File"
✅ Confirm that the file
demo.txtis created successfully and appears in the Sketch Files panel
Step 5: In the Sketch Files panel, double-click on demo.txt to rename it
Step 6: Clear the filename and type demo.obj, then press Enter to confirm the rename
// Paste your code here :)
I reproduced the issue successfully. The validation logic seems to run during file creation but not during rename operations, allowing unsupported extensions like .obj to bypass the whitelist.
I’d be happy to work on a fix for this. Please assign this issue to me if available.
What makes this a bad thing?
Description
This PR resolves the file type restriction bypass when renaming files (fixes #4102).
Currently, the editor blocks invalid file extensions during creation (e.g., test.obj), but does not perform the same validation during a rename, allowing a user to rename test.js to test.obj and bypass the whitelist entirely.
Changes
- FileNode.jsx:
- Imported
CREATE_FILE_REGEXandshowToast(usingshowToastActionto prevent ESLintno-shadowcollision). - Added a whitelist check to
validateFileName()for file types. - Triggers the
NewFileModal.InvalidTypetoast error on rename failure and reverts to the previous name.
- Imported
- FileNode.unit.test.jsx:
- Mocked the
showToastprop in the test setup. - Adjusted unit tests to use valid whitelisted extensions (
.js/.json) for renaming scenarios. - Added a new unit test
cannot change to an invalid extensionto confirm it triggers the toast and blocks the rename.
- Mocked the
Verification
- Verified all client unit tests pass successfully:
npm run test -- client/modules/IDE/components/FileNode.unit.test.jsx(9/9 passed).
Hi @Jatin24062005 Thank you for filing the bug and thank you @Dakshx07 for the fix! Looks great from my end, I'll see if we can merge that PR.
one note @Dakshx07 in order to help everyone contribute without overlapping work, we prefer for contributors to ask to be assigned to an issue before starting work and opening a PR.
Thank you so much @khanniie! Glad the fix helped, and noted on asking for assignment first — I'll definitely do that for future contributions. Thanks again!