@@ -69,19 +69,33 @@ pragma[noinline]
6969Folder getAPackageJSONFolder ( ) { result = any ( PackageJSON json ) .getFile ( ) .getParentContainer ( ) }
7070
7171/**
72- * Gets a reference to `dirname` that might cause information to be leaked.
73- * That can happen if there is a `package.json` file in the same folder.
74- * (It is assumed that the presence of a `package.json` file means that a `node_modules` folder can also exist.
72+ * Gets a reference to `dirname`, the home folder, the current working folder, or the root folder.
73+ * All of these might cause information to be leaked.
74+ *
75+ * For `dirname` that can happen if there is a `package.json` file in the same folder.
76+ * It is assumed that the presence of a `package.json` file means that a `node_modules` folder can also exist.
77+ *
78+ * For the root/home/working folder, they contain so much information that they must leak information somehow (e.g. ssh keys in the `~/.ssh` folder).
7579 */
76- DataFlow:: Node dirname ( ) {
80+ DataFlow:: Node getALeakingFolder ( string description ) {
7781 exists ( ModuleScope ms | result .asExpr ( ) = ms .getVariable ( "__dirname" ) .getAnAccess ( ) ) and
78- result .getFile ( ) .getParentContainer ( ) = getAPackageJSONFolder ( )
82+ result .getFile ( ) .getParentContainer ( ) = getAPackageJSONFolder ( ) and
83+ description = "the folder " + result .getFile ( ) .getParentContainer ( ) .getRelativePath ( )
84+ or
85+ result = DataFlow:: moduleImport ( "os" ) .getAMemberCall ( "homedir" ) and
86+ description = "the home folder "
87+ or
88+ result .mayHaveStringValue ( "/" ) and
89+ description = "the root folder"
90+ or
91+ result .getStringValue ( ) = [ "." , "./" ] and
92+ description = "the current working folder"
7993 or
80- result .getAPredecessor ( ) = dirname ( )
94+ result .getAPredecessor ( ) = getALeakingFolder ( description )
8195 or
8296 exists ( StringOps:: ConcatenationRoot root | root = result |
8397 root .getNumOperand ( ) = 2 and
84- root .getOperand ( 0 ) = dirname ( ) and
98+ root .getOperand ( 0 ) = getALeakingFolder ( description ) and
8599 root .getOperand ( 1 ) .getStringValue ( ) = "/"
86100 )
87101}
@@ -94,11 +108,7 @@ DataFlow::Node getAPrivateFolderPath(string description) {
94108 result = getANodeModulePath ( path ) and description = "the folder \"" + path + "\""
95109 )
96110 or
97- result = dirname ( ) and
98- description = "the folder " + result .getFile ( ) .getParentContainer ( ) .getRelativePath ( )
99- or
100- result .getStringValue ( ) = [ "." , "./" ] and
101- description = "the current working folder"
111+ result = getALeakingFolder ( description )
102112}
103113
104114/**
0 commit comments