Skip to content

make buildOpenApiUrl return a URI#1242

Merged
cortlepp merged 1 commit into
apache:masterfrom
rootvector2:swagger-ui-url-escape
Jul 7, 2026
Merged

make buildOpenApiUrl return a URI#1242
cortlepp merged 1 commit into
apache:masterfrom
rootvector2:swagger-ui-url-escape

Conversation

@rootvector2

@rootvector2 rootvector2 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

per review, buildOpenApiUrl now returns a java.net.URI instead of a String, and the URI is passed through generateSwaggerUIHtml / generateSwaggerUIScript right up to the point it's embedded in the html, so the url is parsed and validated at construction rather than being a raw string. the original escapeJs approach and its test are dropped.

@cortlepp

cortlepp commented Jul 7, 2026

Copy link
Copy Markdown
Member

Hey,
thanks for looking into this, but I don't think this is valid. First of all, the operator of the axis instance chooses the server name, that is not in our threat model (since the administrator can obviously change the behavior of axis, it's kind of their job). Secondly, even if they wanted to deploy the server to a malicious host name, that would still have to be a valid host name in order for any of this to work, and you just can't put a script tag inside of a host name (see the relevant RFCs for details).

I'd agree though that it would look nicer (and be more obviously correct) if buildOpenApiUrl would return a URI instead of a String (and we would pass that around right until we embed it into the html). If you want to improve the clarity of the code in that way I'd be open to reviewing such an MR.

@rootvector2 rootvector2 force-pushed the swagger-ui-url-escape branch from 45736f1 to 212440b Compare July 7, 2026 07:26
@rootvector2 rootvector2 changed the title escape openapi url in swagger-ui init script make buildOpenApiUrl return a URI Jul 7, 2026
@rootvector2

Copy link
Copy Markdown
Contributor Author

fair enough on the threat model. reworked it along the lines you suggested: buildOpenApiUrl now returns a java.net.URI that gets passed around until it's embedded in the html, so the url is parsed and validated at construction instead of being a raw string. dropped escapeJs and its test, and updated the title/body to match. mvn -pl modules/openapi test passes.

@cortlepp cortlepp merged commit 580ebc8 into apache:master Jul 7, 2026
5 checks passed
@cortlepp

cortlepp commented Jul 7, 2026

Copy link
Copy Markdown
Member

Thanks @rootvector2 !

@rootvector2

Copy link
Copy Markdown
Contributor Author

thanks for the merge, glad this one landed.

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.

2 participants