[Bug]: [API Portal] REST API accepts view handles that are not URL-safe

Abierto
#4,142 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, openapi
Área
api

Línea de trabajo

Start with addView in portals/api-portal/src/services/apiMetadataService.js near line 1606, which copies req.body.id into handle unvalidated. Then check ViewCreateRequest.id in portals/api-portal/resources/openapi/api-portal-openapi-spec-v0.9.yaml near line 7926 and add a pattern matching the Settings UI rule. Done when POST with uppercase, spaced or slashed handles returns 400 and nothing is stored, and the same rule applies in updateView. Existing invalid views are a separate decision.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Aspect/API Severity/Minor Type/Bug
Please select the area the issue is related to

Developer Portal

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

POST /api-portal/api/v0.9/views stores the view handle (id) exactly as sent, without validating it. Handles with uppercase letters, spaces or slashes are accepted with 201.

The handle becomes part of the view's URL (/views/<handle>/...), so it must be URL-safe. The Settings UI enforces this with "Handle must be lowercase letters, numbers and hyphens only.", but the REST API doesn't, so scripts and other API clients can create views the UI would refuse.

Expected: each invalid handle is refused with 400, and nothing is stored.

Actual: each invalid handle gets 201 and can be read back with 200.

Handle sent Problem POST /views GET /views/<encoded handle>
Manual-Upper-View Not lowercase 201 200
manual-spaced view Contains a space 201 200
manual-slash/apis Contains a slash 201 200

Impact

  • A slash reads as another URL path segment, and a space has to be encoded, so these handles don't work as normal view URLs.
  • Mixed-case handles are inconsistent with the lowercase handles the portal generates.
  • The Settings form validates the handle on save, so it refuses to save a view with an invalid handle until the handle is changed.

Cause

  • addView copies req.body.id into handle without validation (portals/api-portal/src/services/apiMetadataService.js:1606).
  • ViewCreateRequest.id has no pattern and is documented as "stored as-is", so the OpenAPI request validator allows it (portals/api-portal/resources/openapi/api-portal-openapi-spec-v0.9.yaml:7926).

Suggested fix

  • Add a pattern to ViewCreateRequest.id that matches the rule the UI enforces, and remove "stored as-is" from its description.
  • Apply the same rule to handle changes in updateView and to any other path that creates views.
  • Decide separately how to handle views already stored with invalid handles.
Steps to Reproduce
  1. Get a bearer token for an administrator and set BASE to the portal's REST API, for example https://localhost:9543/api-portal/api/v0.9.

  2. Create a view with a valid handle as a control. It returns 201.

    curl -sk -w '\nHTTP %{http_code}\n' -X POST "$BASE/views" \
      -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
      -d '{"id":"manual-valid-view","displayName":"Valid View"}'
    
  3. Create a view with an uppercase handle. It returns 201; 400 is expected.

    curl -sk -w '\nHTTP %{http_code}\n' -X POST "$BASE/views" \
      -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
      -d '{"id":"Manual-Upper-View","displayName":"Refused View"}'
    
  4. Read it back. It returns 200; 404 is expected.

    curl -sk -w '\nHTTP %{http_code}\n' "$BASE/views/Manual-Upper-View" -H "Authorization: Bearer $ADMIN_TOKEN"
    
  5. Repeat steps 3 and 4 with manual-spaced view (read back as manual-spaced%20view) and manual-slash/apis (read back as manual-slash%2Fapis). The results are the same.

Severity Level of the Issue

Severity/Minor (Non-critical functionality. Can be fixed in future releases)

Environment Details (with versions)
  • API Portal 1.1.0-m6-SNAPSHOT, built locally from source
  • Platform API 0.17.0-SNAPSHOT, for sign-in
  • SQLite, running with Docker Compose on macOS
Lenguaje dominante
Go
Estrellas
85
Forks
137
Merge medio
1 d 12 h
PR fusionados (30 d)
247

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de wso2/api-platform

Todos los issues de wso2/api-platform

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.