Skip to content

Commit

Permalink
fix: obfuscate based on name suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkrzyskow committed Sep 25, 2024
1 parent 5efd849 commit 4ee97b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 8 additions & 0 deletions mkdocs_nype/plugins/nype_tweaks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def is_hex_string(text: str):
def obfuscate(text: str):
"""Turn plain text into base64 and obfuscate it as hex"""

if not isinstance(text, str):
raise ValueError(
f"HEX obfuscation is only avaialble for text strings not {type(text)}({text})"
)

# side-effect, but we want consistent results
text = text.strip()

if is_hex_string(text):
return text

Expand Down
15 changes: 7 additions & 8 deletions mkdocs_nype/templates/nype-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@
{% endif -%}

{#- Obfuscate values that should not be in plain text in the HTML -#}
{% if page_nype_config.obfuscate_keys %}
{% for name, value in page_nype_config.js.items() %}
{% if name in page_nype_config.obfuscate_keys %}
{% set value = (value | obfuscate) %}
{% endif %}
{%- set _ = page_nype_config.js.update({ name: value })-%}
{% endfor %}
{% endif %}

{% for name, value in page_nype_config.js.items() %}
{% if name.endswith("_hex") %}
{% set value = (value | obfuscate) %}
{% endif %}
{%- set _ = page_nype_config.js.update({ name: value })-%}
{% endfor %}
<script>
const nypeScriptConfig = JSON.parse('{{ page_nype_config.js | tojson }}');
</script>
Expand Down

0 comments on commit 4ee97b4

Please sign in to comment.