Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@aka76bm
Copy link
Owner

@aka76bm aka76bm commented Sep 22, 2025

Potential fix for https://github.com/aka76bm/cli/security/code-scanning/1

To fix this issue, we must check that the input port value falls into the valid range for a port (0 < port <= 65535) before converting from int to uint16. In internal/codespaces/portforwarder/port_forwarder.go, the problematic code is on line 267, where uint16(remotePort) is called as an argument to DeleteTunnelPort. To address this, introduce a bounds check before the conversion, and only proceed if the port is valid—otherwise, return an error (or fallback as appropriate for the context). The fix should also preferably use a helper function for conversion, similar to the convertIntToUint16 function used elsewhere in the file (see lines 230-233). If convertIntToUint16 exists, use it instead for consistency.

Specifically:

  • In UpdatePortVisibility, add logic to convert and check remotePort safely before deleting the port.
  • If convertIntToUint16 exists and is suitable, reuse it; otherwise, define/import such a helper.
  • Imports: If the helper uses math (for MaxUint16), ensure the import exists.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…ween integer types

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: MUSTAPHA BARKI <[email protected]>
@aka76bm aka76bm marked this pull request as ready for review September 22, 2025 02:29
@aka76bm aka76bm merged commit 767ddd5 into trunk Sep 22, 2025
12 of 13 checks passed
aka76bm added a commit that referenced this pull request Sep 28, 2025
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