CVE-2023-38695 (published 2023-08-04T18:15Z)

cypress-image-snapshot shows visual regressions in Cypress with jest-image-snapshot. Prior to version 8.0.2, it's possible for a user to pass a relative file path for the snapshot name and reach outside of the project directory into the machine running the test. This issue has been patched in version 8.0.2.\n\n\n

CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-22
cwe_name: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
description: The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
extended_description: 
            Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin" to access unexpected files. This is referred to as absolute path traversal.
         
         

Fix information:
repo_url: https://github.com/simonsmith/cypress-image-snapshot
commit_details: repo_url: https://github.com/simonsmith/cypress-image-snapshot
author: Simon Smith
author_date: 2023-07-31 20:35:35+01:00
msg: fix: sanitise snapshot filenames

Prevents potential for tests to create directories/images outside of the repository
root. Makes use of the Cypress screenshot path which has already been
sanitised

Fixes #15
repository: repo_url: https://github.com/simonsmith/cypress-image-snapshot
repo_name: simonsmith/cypress-image-snapshot
description: Catch visual regressions in Cypress with jest-image-snapshot
repo_language: TypeScript
owner: simonsmith
file_changes: filename: matchImageSnapshot.cy.ts
change_type: ModificationType.MODIFY
diff: @@ -11,6 +11,11 @@ it('name and selector', () => {
   cy.get('body').matchImageSnapshot('with custom name')
 })
 
+it('file name should ignore directories', () => {
+  cy.get('h1').matchImageSnapshot('../../../ignore-relative-dirs')
+  cy.get('h1').matchImageSnapshot('ignore/folders/image')
+})
+
 // next two tests use blackout to change
 // the snapshot image. Also validates options
 it('name and options', () => {

programming_language: TypeScript
filename: matchImageSnapshot.cy.ts
change_type: ModificationType.MODIFY
diff: @@ -6,3 +6,7 @@ beforeEach(() => {
 it('takes a snapshot of the page', () => {
   cy.matchImageSnapshot()
 })
+
+it('file name should ignore directories', () => {
+  cy.get('h1').matchImageSnapshot('../../../ignore-relative-dirs')
+})

programming_language: TypeScript
filename: plugin.ts
change_type: ModificationType.MODIFY
diff: @@ -55,8 +55,7 @@ const runImageDiffAfterScreenshot = async (
     return {path: screenshotPath}
   }
 
-  // name of the screenshot without the Cypress suffixes for test failures
-  const snapshotName = screenshotConfig.name.replace(/ \(attempt [0-9]+\)/, '')
+  const snapshotName = path.basename(screenshotConfig.path, '.png')
 
   const receivedImageBuffer = await fs.readFile(screenshotPath)
   await fs.rm(screenshotPath)

programming_language: JavaScript