michel-kraemer / citeproc-java

📘 A Citation Style Language (CSL) processor for Java.
Apache License 2.0
89 stars 17 forks source link

only create links for trusted href values #242

Open nhnb opened 3 months ago

nhnb commented 3 months ago

At the moment, a url value of javascript:alert(document.domain) is converted to <a href="javascript:alert(document.domain)">javascript:alert(document.domain)</a>.

I belief the risk is very low because the javascript code is clearly visible. But it might be a good idea to fix this issue anyway.

Steps to reproduce:

    public static void main(String[] args) throws IOException {
        CSLItemData item = new CSLItemDataBuilder()
            .type(CSLType.ARTICLE_JOURNAL)
            .title("Protein measurement with the Folin phenol reagent")
            .author(
                new CSLNameBuilder().given("G").family("Krüger").build()
            )
            .URL("javascript:alert(document.domain)")
            .build();

        ItemDataProvider provider = new ListItemDataProvider(item);
        CSL csl = new CSL(provider, "ieee-with-url");
        csl.registerCitationItems(item.getId());
        csl.setConvertLinks(true);
        csl.setOutputFormat("html");

        String res = csl.makeBibliography().makeString();
        System.out.println(res);
    }
michel-kraemer commented 3 months ago

Nice catch! Thank you. I'll merge the PR together with your other one (#243).

github-actions[bot] commented 1 month ago

This pull request has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in two weeks if no further activity occurs. Thank you for your contributions.