-
-
Save codingo/9fc779b45a16b6a49edd1e20d941baa3 to your computer and use it in GitHub Desktop.
Identify "href" usages in SPAs (ReactJS), i.e., free javascript: XSS
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
| import re | |
| import sys | |
| VULNERABLE_HREF = r'href: [^"].+[^\s;,]' | |
| STATE_VALUES = r'\.setState\({([\s\S]*?)}\)' | |
| #false_positives = ("this.props.team.", "constants.") | |
| def find_state_candidates(name, states): | |
| candidates = [] | |
| for state in states: | |
| for param in state.split('\n'): | |
| param = param.rstrip(',;').strip() | |
| if param.split(':')[0] == name: | |
| candidates.append(param.split(':')[1].strip()) | |
| return candidates | |
| if __name__ == '__main__': | |
| if len(sys.argv) != 2: | |
| print("Usage: %s beautified.js" % sys.argv[0]) | |
| sys.exit() | |
| with open(sys.argv[1], 'r', errors="ignore") as f: | |
| content = f.read() | |
| hrefs = re.findall(VULNERABLE_HREF, content) | |
| states = re.findall(STATE_VALUES, content, flags=re.MULTILINE) | |
| states = [re.sub(' +', ' ', state).strip() for state in states] | |
| for href in hrefs: | |
| value = href.split(' ')[1] | |
| # if not value.startswith(false_positives): | |
| if value.startswith('this.state.'): | |
| print("%s (%s)" % (href, find_state_candidates(value.split('.')[2], states))) | |
| else: | |
| print(href) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment