def sanitize_indexes(indexes: list, user_input: str) -> list:
    """
    Given a list of valid indexes and a comma-separated
    string of (supposedly) user-entered indexes,
    it returns the list of indexes that are valid.

    :param list indexes: list of permitted indexes
    :param str user_input: comma-separated list of ind.
    :return list: list of valid indexes
    """
    res = set()
    max_val = len(indexes)

    for index in user_input.split(","):
        index = index.strip()
        if index.isdigit() and int(index)-1 < max_val:
            res.add(int(index)-1)
    return list(res)