Validate URL link is allowed in output. This validator can prohibit more than really needed to prevent XSS. It's a tradeoff to keep code simple and to be secure by default. Note: url should be normalized at this point, and existing entities decoded.
(url: str, validator: Callable[[str], bool] | None = None)
| 68 | |
| 69 | |
| 70 | def validateLink(url: str, validator: Callable[[str], bool] | None = None) -> bool: |
| 71 | """Validate URL link is allowed in output. |
| 72 | |
| 73 | This validator can prohibit more than really needed to prevent XSS. |
| 74 | It's a tradeoff to keep code simple and to be secure by default. |
| 75 | |
| 76 | Note: url should be normalized at this point, and existing entities decoded. |
| 77 | """ |
| 78 | if validator is not None: |
| 79 | return validator(url) |
| 80 | url = url.strip().lower() |
| 81 | return bool(GOOD_DATA_RE.search(url)) if BAD_PROTO_RE.search(url) else True |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…