,> As discussed in the issues you linked to, the reason for using a
.crswap file is to give local security scanning software the
opportunity to examine the modified file before the changes are
committed to a file that may be interpreted by other applications on
the system.
The proferred reasoning in the linked issues makes no sense to me. For
the following reasons:
1. If a user is committed to scanning files they can scan the actual
file being written. Writing a .crswap file first doesn't change
anything relevant to scanning files.
> For example, a malicious site could try to exploit an issue in the system's JPEG parser for thumbnail image creation.
2. Nothing is stopping the same exploit from happening when the
.crswap file is written.
> By writing to the .crswap file first and then asking the system to run security scans (e.g. Windows Defender) before the contents are moved to the .jpg file this exploit is mitigated.
3. Nothing is stopping the system from scanning the actual file Or
scanning the .crswap file. Nothing is gained by writing to a .crswap
file first.
> On platforms and filesystems where this is possible renaming the .crswap file does not require copying any of the contents.
4. Not following. Just write the actual file instead of those
Chromium-specific .crswap files.
> If the application needs the performance of direct file writes it can use the Origin Private File System which mitigates the concern above by storing files in a site-specific storage area which is not accessed by other applications on the system.
5. That's simply technically untrue. Here's how to get the files and
directories from "Origin Private File System", which is just writing
to the "File System" folder in Chromium/Chrome configuration folder
https://gist.github.com/guest271314/78372b8f3fabb1ecf95d492a028d10dd#file-createreadwritedirectoriesinbrowser-js-L118-L162
// Helper function for filesystem *development*
// Get directory in origin private file system from Chrome configuration folder.
// fetch() file: protocol with "file://*/*" or "<all_urls>" in
"host_permissions"
// in browser extension manifest.json
async function parseChromeDefaultFileSystem(path) {
try {
const set = new Set([
32, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 64, 65, 66, 67, 68,
69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 95, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110,
111, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122,
]);
const request = await fetch(path);
const text = (await request.text()).replace(/./g, (s) =>
set.has(s.codePointAt()) ? s : "");
const files = [
...new Set(
text.match(
/00000\d+[A-Za-z-_.0-9\s]+\.crswap/g,
),
),
].map((s) => {
const dir = [...new Set(text.slice(0,
text.indexOf(s)).match(/(?<=[@\s]|CHILD_OF:0:)([\w-_])+(?=Ux)/g).map((d)
=>
d.split(/\d+|D140/)
))].flat().pop();
const re = /00000[\d\s]+|\.crswap/g;
const [key] = s.match(re);
return ({
[key]: s.replace(re, ""),
dir
})
});
return {
name: files[0].dir,
files
}
} catch (e) {
console.error(e);
}
}
// let paths = await
parseChromeDefaultFileSystem("file:///home/user/.config/chromium/Default/File\
System/021/t/Paths/000003.log");
// console.log(JSON.stringify(paths, null, 2));
6. Lastly. I'm a programmer and a user. If I decide to not scan files
I download from the Web that should be my choice. Just like if I don't
want Google Search to be my default search engine. Simply provide a
flag for users on their own machine to get rid of writing that useless
.crswap file.