Created
April 7, 2019 20:26
-
-
Save Buggytheclown/84f279e72a2d5383bc04408fd445ad37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lookLike(prop1, asProp2) { | |
if (prop1 === asProp2) { | |
return true; | |
} | |
if (typeof prop1 !== "object" || typeof asProp2 !== "object") { | |
return false; | |
} | |
return Object.entries(asProp2).every(([k, v]) => lookLike(prop1[k], v)); | |
} | |
export default function(context) { | |
return { | |
["ExpressionStatement, AssignmentExpression"](node) { | |
const locationReplace = { | |
expression: { | |
callee: { | |
type: "MemberExpression", | |
property: { | |
type: "Identifier", | |
name: "replace" | |
}, | |
object: { | |
type: "MemberExpression", | |
property: { | |
type: "Identifier", | |
name: "location" | |
} | |
} | |
} | |
} | |
}; | |
const locationAssign = { | |
expression: { | |
callee: { | |
type: "MemberExpression", | |
property: { | |
type: "Identifier", | |
name: "assign" | |
}, | |
object: { | |
type: "MemberExpression", | |
property: { | |
type: "Identifier", | |
name: "location" | |
} | |
} | |
} | |
} | |
}; | |
const locationHrefAssignment = { | |
left: { | |
type: "MemberExpression", | |
property: { | |
type: "Identifier", | |
name: "href" | |
}, | |
object: { | |
type: "MemberExpression", | |
property: { | |
type: "Identifier", | |
name: "location" | |
} | |
} | |
} | |
}; | |
if (!lookLike(node, locationReplace) && !lookLike(node, locationAssign) && !lookLike(node, locationHrefAssignment)) return; | |
context.report({ | |
node, | |
message: "direct url manipulation is not safe for cordova app, use locationReplace helpers instead" | |
}); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment