Skip to content

[2103] fix: Adds author xml escaping#54

Merged
freakboy3742 merged 7 commits intobeeware:mainfrom
caydnn:Fix2103
Oct 8, 2025
Merged

[2103] fix: Adds author xml escaping#54
freakboy3742 merged 7 commits intobeeware:mainfrom
caydnn:Fix2103

Conversation

@caydnn
Copy link
Contributor

@caydnn caydnn commented Apr 19, 2025

Adds XMLEscape extension to author name usage in {{ cookiecutter.app_name }}.xws

Partially fixes beeware/briefcase#2103

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does appear that it resolves the immediate issue reported by beeware/briefcase#2103; however, two notes:

  1. We generally don't create a new template variable when the result can be completely derived with filters. module_name and app_name use template-pre-processing - but that's just for the default value. They can (and, under normal circumstances, will be) be independently provided as part of the template context. So - preference would be to apply the xml_escape filter wherever the variable is used, rather than remember that there's a different variable for the xml excaped author name.
  2. While this literally addresses the reported bug with author name, are there any other attributes that can/should be escaped? It would appear that any variable used an attribute or as a value inside a tag should be escaped. Since we're currently looking at escaping, it makes sense to do a comprehensive pass and check every variable insertion to see if it could be problematic.

@caydnn
Copy link
Contributor Author

caydnn commented Apr 21, 2025

Ok no worries Russell, I'll remove the new template and check for other attributes that could be escaped. :)
I sort of made this to see if I was on the right path so thanks for the feedback!

@caydnn
Copy link
Contributor Author

caydnn commented Oct 7, 2025

  1. We generally don't create a new template variable when the result can be completely derived with filters. module_name and app_name use template-pre-processing - but that's just for the default value. They can (and, under normal circumstances, will be) be independently provided as part of the template context. So - preference would be to apply the xml_escape filter wherever the variable is used, rather than remember that there's a different variable for the xml excaped author name.
  2. While this literally addresses the reported bug with author name, are there any other attributes that can/should be escaped? It would appear that any variable used an attribute or as a value inside a tag should be escaped. Since we're currently looking at escaping, it makes sense to do a comprehensive pass and check every variable insertion to see if it could be problematic.

Sorry about the wait, but these points should be resolved now. I did a lot of xml_escapes where I thought would be necessary. Please let me know if I've gone too far when you get a chance :)

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; although it's probably a little too safe :-) There's a few tags (flagged inline) that can't contain unsafe XML characters by definition, so they don't need to be protected.


<Feature Id="DefaultFeature">
<ComponentGroupRef Id="{{ cookiecutter.module_name }}_COMPONENTS" />
<ComponentGroupRef Id="{{ cookiecutter.module_name|xml_escape }}_COMPONENTS" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module name should be XML-safe - it has to be a Python identifier.

Suggested change
<ComponentGroupRef Id="{{ cookiecutter.module_name|xml_escape }}_COMPONENTS" />
<ComponentGroupRef Id="{{ cookiecutter.module_name }}_COMPONENTS" />

{% endif -%}
{% if cookiecutter.author_email -%}
<Property Id="ARPCONTACT" Value="{{ cookiecutter.author_email }}" />
<Property Id="ARPCONTACT" Value="{{ cookiecutter.author_email|xml_escape }}" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fairly certain email addresses can't contain any XML unsafe characters

</StandardDirectory>

<ComponentGroup Id="{{ cookiecutter.module_name }}_COMPONENTS">
<ComponentGroup Id="{{ cookiecutter.module_name|xml_escape }}_COMPONENTS">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module name must be XML safe - it's a Python identifier.

Comment on lines +84 to +92
Id="ProductIcon.{{ document_type_id|xml_escape }}"
Source="{{ cookiecutter.app_name }}-{{ document_type_id|xml_escape }}.ico" />
<ProgId
Id="{{ cookiecutter.bundle }}.{{ cookiecutter.app_name }}.{{ document_type_id }}"
Description="{{ document_type.description }}"
Id="{{ cookiecutter.bundle|xml_escape }}.{{ cookiecutter.app_name|xml_escape }}.{{ document_type_id|xml_escape }}"
Description="{{ document_type.description|xml_escape }}"
Icon="ProductIcon.{{ document_type_id }}">
<Extension
Id="{{ document_type.extension }}"
ContentType="{% if document_type.get('mime_type') %}{{ document_type.mime_type }}{% else %}application/x-{{ cookiecutter.app_name }}-{{ document_type_id }}{% endif %}">
Id="{{ document_type.extension|xml_escape }}"
ContentType="{% if document_type.get('mime_type') %}{{ document_type.mime_type|xml_escape }}{% else %}application/x-{{ cookiecutter.app_name }}-{{ document_type_id }}{% endif %}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these are a bit enthusiastic in what they're protecting:

  • bundle must be a reversed domain name, so it must be XML safe
  • app_name is either a python identifier, or an identifier with _ replace with - - so it must be XML safe
  • A file extension is highly unlikely to be XML safe, as is a document type ID. I guess it doesn't hurt to keep those protected, but it probably isn't needed.

@caydnn
Copy link
Contributor Author

caydnn commented Oct 8, 2025

I've taken out extra safe escapes you've flagged Russell, hopefully this is good to go now

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Awesome - nice work.

@freakboy3742 freakboy3742 merged commit a476313 into beeware:main Oct 8, 2025
23 checks passed
@freakboy3742
Copy link
Member

@caydnn Also - noting that this set of change will need to be backported to the Windows app template as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Briefcase fails to escape ampersands in company name when generating [appname].wxs when packaging for Windows

2 participants