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

dont allow port mappings to internal ports 21, 23, 25, 53, 143 #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1/providers/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,10 +1524,13 @@ def add_instance_port(
external: int,
internal: int
):
forbidden_ports = [21, 23, 25, 53, 143]
port_map = self.get_port_forward_map()

if external in port_map:
raise exceptions.resource.Unavailable(f"Cannot map port {external} to {internal}, this port is currently taken by another user/another one of your instances")
if internal in forbidden_ports:
raise exceptions.resource.Unavailable(f"Cannot map port {external} to {internal}, internal port forbidden")

instance.metadata.network.ports[external] = internal
self.write_out_instance_metadata(instance)
Expand Down
7 changes: 6 additions & 1 deletion ui/src/components/InstancesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ export interface ConfirmCancelAction {

const VHostValidation = new RegExp('^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$')
const PortValidation = new RegExp('^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$')
const portAllowed = (p: string) => {
const forbiddenPorts = ['21', '23', '25', '53', '143']
return !forbiddenPorts.includes((p))
}

export default Vue.extend({
components: {
Expand Down Expand Up @@ -847,7 +851,8 @@ export default Vue.extend({
portRules (): ((v: string) => (string | boolean))[] {
return [
(v: string) => !!v || 'Port required',
(v: string) => PortValidation.test(v) || 'Port must be between 0 and 65355'
(v: string) => PortValidation.test(v) || 'Port must be between 0 and 65355',
(v: string) => portAllowed(v) || 'You should not create mappings to port ' + v
]
},

Expand Down