-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin Migrating ClaroDocs to Closure Templates Rather Than Manual Str…
…ingBuilder The entire motivation for this is to have some confidence that the html generated can't become the target of XSS vulnerabilities since I'm generating html based on user given strings in .claro_module_api files (most egregiously via the doc comments I'll start parsing for each exported item). This extra headache that I'm going through is important because the design of ClaroDocs is built around the idea that ALL dep modules, including 3rd party deps, have their docs inlined into the docs for any given claro binary. By doing this extra work to ensure that everything is properly escaped, users should be able to blindly host ClaroDocs anywhere and be confident that there's no potential vulnerability. There're still more pieces to migrate, and unfortunately this will never be particularly clean since the public Soy (Closure) Templates don't support using Protos in the java backend at the moment...
- Loading branch information
1 parent
bfa8c47
commit eb1d5ae
Showing
18 changed files
with
794 additions
and
212 deletions.
There are no files selected for viewing
This file contains 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
15 changes: 15 additions & 0 deletions
15
src/java/com/claro/module_system/clarodocs/html_rendering/BUILD
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_java_template_library") | ||
|
||
closure_java_template_library( | ||
name = "html_soy", | ||
srcs = [ | ||
"code_block.soy", | ||
"procedures.soy", | ||
"tokens.soy", | ||
"types.soy", | ||
"utils.soy", | ||
], | ||
java_package = "com.claro.module_system.clarodocs.html_rendering", | ||
visibility = ["//src/java/com/claro/module_system/clarodocs/html_rendering:__subpackages__"], | ||
) | ||
|
||
java_library( | ||
name = "util", | ||
srcs = ["Util.java"], | ||
deps = [":html_soy"], | ||
visibility = ["//src/java/com/claro/module_system/clarodocs/html_rendering:__subpackages__"], | ||
) |
14 changes: 14 additions & 0 deletions
14
src/java/com/claro/module_system/clarodocs/html_rendering/Util.java
This file contains 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
This file contains 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
13 changes: 13 additions & 0 deletions
13
src/java/com/claro/module_system/clarodocs/html_rendering/code_block.soy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{namespace codeblock} | ||
|
||
|
||
{template .code} | ||
{@param codeContent: html} | ||
{@param class: string} | ||
{@param id: string} | ||
<pre> | ||
<code class="{$class}" id="{$id}"> | ||
{$codeContent} | ||
</code> | ||
</pre> | ||
{/template} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
87 changes: 87 additions & 0 deletions
87
src/java/com/claro/module_system/clarodocs/html_rendering/procedures.soy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{namespace procedures} | ||
|
||
|
||
{template .exportedProcedure} | ||
{@param name: string} | ||
{@param? requiredContracts: list<[contractName: string, genericTypeParams: list<string>]>} | ||
{@param? genericTypeParams: list<string>} | ||
{@param? argTypes: list<html>} | ||
{@param? outputType: html} | ||
|
||
{call codeblock.code} | ||
{param codeContent kind="html"} | ||
{call .procedureSignature data="all" /} | ||
{/param} | ||
{param class kind="text"}{call .procedureDefClass /}{/param} | ||
{param id: $name /} | ||
{/call} | ||
{/template} | ||
|
||
{template .procedureDefClass kind="text" visibility="private"} | ||
procedure-def | ||
{/template} | ||
|
||
{template .requires visibility="private"} | ||
{@param requiredContracts: list<[contractName: string, genericTypeParams: list<string>]>} | ||
{call tokens.REQUIRES /}( | ||
{for $contract in $requiredContracts} | ||
{$contract.contractName}{call tokens.LT /} | ||
{for $genericTypeParam, $i in $contract.genericTypeParams} | ||
{if $i > 0}, {/if} // Comma after all but first. | ||
{$genericTypeParam} | ||
{/for} | ||
{call tokens.GT /} | ||
{/for} | ||
) | ||
{/template} | ||
|
||
{template .args visibility="private"} | ||
{@param argTypes: list<html>} | ||
{for $arg, $i in $argTypes} | ||
{if $i > 0}, {/if} | ||
arg{$i}{call tokens.COLON /} {$arg} | ||
{/for} | ||
{/template} | ||
|
||
{template .procedureSignature visibility="private"} | ||
{@param name: string} | ||
{@param? requiredContracts: list<[contractName: string, genericTypeParams: list<string>]>} | ||
{@param? genericTypeParams: list<string>} | ||
{@param? argTypes: list<html>} | ||
{@param? outputType: html} | ||
|
||
{if $requiredContracts} | ||
{call .requires} | ||
{param requiredContracts: $requiredContracts /} | ||
{/call}<br> | ||
{/if} | ||
{if $argTypes} | ||
{if $outputType} | ||
{call tokens.FUNCTION /} | ||
{else} | ||
{call tokens.CONSUMER /} | ||
{/if} | ||
{else} | ||
{call tokens.PROVIDER /} | ||
{/if} | ||
{sp}{$name} | ||
{if $genericTypeParams} | ||
{call tokens.LT /} | ||
{for $genericTypeParam, $i in $genericTypeParams} | ||
{if $i > 0}, {/if} | ||
{$genericTypeParam} | ||
{/for} | ||
{call tokens.GT /} | ||
{/if} | ||
( | ||
{if $argTypes} | ||
{call .args} | ||
{param argTypes: $argTypes /} | ||
{/call} | ||
{/if} | ||
) | ||
{if $outputType} | ||
{sp}{call tokens.ARROW /}{sp}{$outputType} | ||
{/if} | ||
{call tokens.SEMICOLON /} | ||
{/template} |
This file contains 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
Oops, something went wrong.