OWASP / threat-dragon

An open source threat modeling tool from OWASP
https://owasp.org/www-project-threat-dragon/
Apache License 2.0
890 stars 238 forks source link

Use the new File System Access API on Chromium browsers #643

Open martinmarsicano opened 1 year ago

martinmarsicano commented 1 year ago

Describe what problem your feature request solves The actual way of handling local threat models could generate a lot of files because a new file is generated each time a user saves the working threat model.

Describe the solution you'd like On chromium based browsers the new File System Access API should be used (it's the one used in https://vscode.dev/)

Additional context Blog presenting the API: https://developer.chrome.com/articles/file-system-access/

jgadsden commented 1 year ago

Certainly looks good, and we need to make sure that we have support for a wide range of browsers

professorabhay commented 1 year ago

Hey @jgadsden, It seems quite interesting. I have a code snippet in JS for do same. We can implement it !!

// Request file system access
async function requestFileSystemAccess() {
  try {
    const [fileHandle] = await window.showOpenFilePicker();
    const file = await fileHandle.getFile();

    // Read file contents
    const fileContents = await file.text();
    console.log('File contents:', fileContents);

    // Write to a file
    const writableFile = await fileHandle.createWritable();
    await writableFile.write('New content');
    await writableFile.close();
    console.log('File updated successfully!');
  } catch (error) {
    console.error('An error occurred:', error);
  }
}

// Call the function to request file system access
requestFileSystemAccess();
jgadsden commented 1 year ago

Thanks @professorabhay this is useful for sure We need to make sure any changes work for a wide range of browsers as well Chrome / Chromium) and that the desktop version works OK as well

professorabhay commented 1 year ago

Yes @jgadsden, As much I know that File System Access is still missing from some browsers. We need to make some checks while implementing it.

jgadsden commented 1 month ago

showOpenFilePicker is already used, so showSaveFilePicker should also be used on Save