Skip to content

Support logoSize=auto for custom logos #11093

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

paulbrimicombe
Copy link

Addresses #11092

I've added support for logoSize=auto for custom logos. This involves adding the image-width package as a dependency. I've added some unit tests but if you'd like more testing, do please indicate what you'd like me to add.

PR title conventions - https://github.com/badges/shields/blob/master/CONTRIBUTING.md#running-service-tests-in-pull-requests

Can someone give me some guidance as to which tests I should be running for this change (i.e. what to put in the [] in the PR title)?

Copy link
Contributor

Messages
📖 ✨ Thanks for your contribution to Shields, @paulbrimicombe!

Generated by 🚫 dangerJS against 6c9f949

@chris48s
Copy link
Member

Can someone give me some guidance as to which tests I should be running for this change (i.e. what to put in the [] in the PR title)?

You're not modifying any services - its all core - so there’s no need to run any of the service tests here.


Before talking about the code (there are a few things that jump out to me, but I don't think its useful to start commenting on the diff at this stage), the first thing I want to get into is: Looking back over #9191 the reason why we didn't apply this to custom logos was due to the performance considerations necessary for dealing with raster images.

Looking over https://www.npmjs.com/package/image-size one of the bullet points is "Minimal memory footprint - reads only image headers" @LitoMore do you have any thoughts on this as a general approach? (ignoring the code in this PR itself for now). Was this a library you considered?

@chris48s chris48s added the core Server, BaseService, GitHub auth, Shared helpers label May 17, 2025
@LitoMore
Copy link
Contributor

We have been attacked before with endpoint badges. Using image-size to calculate image sizes on our server may introduce potential security issues. Here is a security issue they had before: GHSA-m5qc-5hw7-8vg7.

@paulbrimicombe
Copy link
Author

Thanks for your comments — @chris48s and @LitoMore . I'm happy to close this if you're worried about security issues.

Looking back over #9191 the reason why we didn't apply this to custom logos was due to the performance considerations necessary for dealing with raster images.

Is there an option to support this for custom SVG images only perhaps (without using image-size)? If that's acceptable, let me know.

@chris48s
Copy link
Member

Thanks. Security is a great thing to consider here.

That said, I actually don't think that issue is a reason to discount image-size.

Sometimes software has security issues. It happens to the best of us. It is unrealistic to think that every package we pull in has had zero security issues ever.

What I really want to know in terms of security is: If there are security issues, will they be handled well upstream?

Looking at image-size: The project has a healthy release cadence and they handled this issue by publishing a security advisory, fixing the issue and also backporting that fix back to the previous major version. So I'm not actually super worried by that.

@LitoMore
Copy link
Contributor

Then I think this should be fine, since the base64 image will not be too large, given the URL length limit.

@chris48s
Copy link
Member

@paulbrimicombe I'll try and get back to you with some proper feedback on the code.

I've had a really quick glance but I need to spend a bit more time on this in order to give you (as a first-time contributor) a proper steer on where next. I have quite a bit going on right now so I am probably going to struggle to find that time over the next week or so.

If I haven't replied to this thread in a week can you comment so I get a ping in my notifications. Ta

Copy link
Contributor

github-actions bot commented Jun 1, 2025

🚀 Updated review app: https://pr-11093-badges-shields.fly.dev

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

I've had a proper look over this. Having considered it, I think this is sensible but we need a bit of improvement to the error handling. Thanks

if (logoSize === 'auto') {
const [, base64Image] = overrideLogoSvgBase64.split(';base64,')
const dimensions = base64Image
? imageSize(Buffer.from(base64Image, 'base64'))
Copy link
Member

@chris48s chris48s Jun 1, 2025

Choose a reason for hiding this comment

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

Feels like there is a risk imageSize could throw here on spurious inputs and I don't want that to be an unhandled exception. There's no guarantee what the user has entered here is intelligible.

I think we should wrap the bit where we attempt to decode the base64 and parse the image in a try/catch and either

  • re-throw any decode/parse exception as an InvalidParameter or
  • just ignore it and don't attempt to apply a custom logoWidth (but attempt to render the badge with whatever input we've been given)

Comment on lines +129 to +130
logoWidth =
(dimensions.width / dimensions.height) * DEFAULT_LOGO_HEIGHT
Copy link
Contributor

Choose a reason for hiding this comment

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

The calculation result is possibly Infinity or NaN. We might need to validate the value before applying it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Server, BaseService, GitHub auth, Shared helpers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants