I believe in your question you contradict yourself.
How do I allow javascript:void(0) for use in HTML element attributes
through Content-Security-Policy?
On one hand, you set a Content Security Policy (CSP) header to which you specify a rule which I'm guessing is script-src. A directive used to prevent inline scripts from running.
On the other hand, you want to bypass it and execute inline javascript.
Isn't the header working just as expected?
Adding 'unsafe-inline' will bypass it, but negates the idea of disallowing inline styles and inline scripts (one of the biggest security wins CSP provides).
You can use a nonce-source to only allow specific inline script blocks.
Example:
Content-Security-Policy: script-src 'nonce-2726c7f26c'
Note, you will have to set the same nonce on the element as well.
<script nonce="2726c7f26c">
var inline = 1;
</script>
For your case using forms, the header would be:
Content-Security-Policy: form-action 'nonce-<value>'
Alternatively, you can create hashes from your inline scripts. CSP supports sha256, sha384 and sha512.
Example:
Content-Security-Policy: script-src 'sha256-076c8f1ca6979ef156b510a121b69b6265011597557ca2971db5ad5a2743545f'
Note, that when generating the hash, don't include the tags and note that capitalization and whitespace matter, including leading or trailing whitespace.
<script>var inline = 1;</script>