p5.js-web-editor icon indicating copy to clipboard operation
p5.js-web-editor copied to clipboard

File Type Restriction Bypass via Rename

Open Jatin24062005 opened this issue 7 months ago • 5 comments

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

Image

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.txt is 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 :)

Jatin24062005 avatar Apr 29 '26 10:04 Jatin24062005

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.

VikasKSingh05 avatar May 06 '26 06:05 VikasKSingh05

What makes this a bad thing?

DavieJones49 avatar May 27 '26 23:05 DavieJones49

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_REGEX and showToast (using showToastAction to prevent ESLint no-shadow collision).
    • Added a whitelist check to validateFileName() for file types.
    • Triggers the NewFileModal.InvalidType toast error on rename failure and reverts to the previous name.
  • FileNode.unit.test.jsx:
    • Mocked the showToast prop 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 extension to confirm it triggers the toast and blocks the rename.

Verification

  • Verified all client unit tests pass successfully: npm run test -- client/modules/IDE/components/FileNode.unit.test.jsx (9/9 passed).

Dakshx07 avatar Jun 14 '26 12:06 Dakshx07

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.

khanniie avatar Oct 16 '26 15:10 khanniie

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!

Dakshx07 avatar Oct 16 '26 16:10 Dakshx07