Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEOS-11152] Improve handling special characters in the Simple SVG Renderer #7173

Merged
merged 1 commit into from Nov 20, 2023

Conversation

sikeoka
Copy link
Contributor

@sikeoka sikeoka commented Oct 10, 2023

GEOS-11152 Powered by Pull Request Badge

This PR updates the Simple SVG renderer to properly escape special characters from GeoServer catalog information.
NOTE: This PR only updates code that could be executed through actual GeoServer WMS GetMap requests and ignores any potential issues in dead code.

Checklist

For core and extension modules:

  • New unit tests have been added covering the changes.
  • Documentation has been updated (if change is visible to end users).
  • The REST API docs have been updated (when changing configuration objects or the REST controllers).
  • There is an issue in the GeoServer Jira (except for changes that do not affect administrators or end users in any way).
  • Commit message(s) must be in the form [GEOS-XYZWV] Title of the Jira ticket.
  • Bug fixes and small new features are presented as a single commit.
  • Each commit has a single objective (if there are multiple commits, each has a separate JIRA ticket describing its goal).

@sikeoka sikeoka added backport 2.23.x Instructs the bot to create a 2.23.x backport PR on merge backport 2.24.x Instructs the bot to create a 2.24.x backport PR on merge labels Oct 10, 2023

if (!styleName.startsWith("#")) {
writer.write(" class=\"" + styleName + "\"");
writer.write(" class=\"" + escapeXml10(styleName) + "\"");
Copy link
Member

Choose a reason for hiding this comment

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

Is SVGWriter.encodeAttribute as good as StringEscapeUtils?
Also, groupId is basically the type name... why bother about the type name (admin configured) but not about the attribute names, in SVGWriter.startFeature?

Copy link
Contributor Author

@sikeoka sikeoka Oct 16, 2023

Choose a reason for hiding this comment

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

SVGWriter.encodeAttribute doesn't exist. There is a AttributesSVGHandler.encodeAttribute but that is a private non-static method on a non-static inner class of SVGWriter and, even though it would prevent injection, it may not actually guarantee valid XML output.
SVGWriter has a lot dead code and I only updated code that could actually be run in a live GeoServer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@groldan
Copy link
Member

groldan commented Nov 4, 2023

oh my! What an oldie! that was the very first WMS output format, even before any raster image one IIRC.
There was no pull-push XML API by then, SAX sucked for streaming, and DOM wasn't an option.
You're not up for a re-write using StAX, aren't you?
Glad to see someone is using it though.

@aaime aaime merged commit cc62dbf into geoserver:main Nov 20, 2023
8 checks passed
@aaime
Copy link
Member

aaime commented Nov 20, 2023

The backport to 2.23.x failed:

The process '/usr/bin/git' failed with exit code 1
stderr
error: could not apply da8046ab01... [GEOS-11152] Improve handling special characters in the Simple SVG Renderer
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

stdout
Auto-merging src/wms/src/main/java/org/geoserver/wms/svg/StreamingSVGMap.java
Auto-merging src/wms/src/test/java/org/geoserver/wms/svg/SVGMapProducerTest.java
CONFLICT (content): Merge conflict in src/wms/src/test/java/org/geoserver/wms/svg/SVGMapProducerTest.java

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.23.x 2.23.x
# Navigate to the new working tree
cd .worktrees/backport-2.23.x
# Create a new branch
git switch --create backport-7173-to-2.23.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick da8046ab019dd5e65c8d440ddfeafefe0f7193d4
# Push it to GitHub
git push --set-upstream origin backport-7173-to-2.23.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.23.x

Then, create a pull request where the base branch is 2.23.x and the compare/head branch is backport-7173-to-2.23.x.

@aaime
Copy link
Member

aaime commented Nov 20, 2023

Eventual backport to 2.23.x will have to be manual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.23.x Instructs the bot to create a 2.23.x backport PR on merge backport 2.24.x Instructs the bot to create a 2.24.x backport PR on merge failed backport
Projects
None yet
3 participants