[Bug]: content-length-guardrail policy schema accepts a configuration with neither request nor response

Open Beginner friendly
#4,329 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, yaml
Domain
api, backend

Research direction

Locate the content-length-guardrail policy's policy-definition.yaml and compare its schema with the word-count-guardrail, sentence-count-guardrail, regex-guardrail, and url-guardrail schemas. Add the request-or-response requirement described in the issue, then confirm the schema rejects empty params while accepting a configuration with either request or response. The issue also points to the integration assertion in wso2/gateway-controllers#415.

Written by the indexing model from the issue text.

Description

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

Gateway

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI), Aspect/Configuration (Config files, settings, env vars, defaults)

Description

The content-length-guardrail documentation says: "At least one of request or response must be provided." The policy refuses a configuration with neither. Its schema does not enforce the rule, so such a configuration passes API creation and fails at runtime instead.

The API is created, and every request to the operation then gets HTTP 500. A mistake that should fail the deployment breaks the operation.

Other guardrails in the repository enforce this rule in their schema, for example word-count-guardrail, sentence-count-guardrail, regex-guardrail and url-guardrail:

anyOf:
  - required: [ request ]
  - required: [ response ]

A fix could add the same rule to the policy's policy-definition.yaml.

The integration suite in wso2/gateway-controllers#415 asserts this behaviour.

Steps to Reproduce
  1. Create a REST API with an operation that attaches the policy with empty parameters:
    {"name":"content-length-guardrail","version":"v1","params":{}}
    
  2. The API is created.
  3. Every request to that operation gets HTTP 500. An operation on the same API with a valid configuration still works.
Severity Level of the Issue

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

Environment Details (with versions)
  • Policy: content-length-guardrail v1.1.0, wso2/gateway-controllers main (4f1520a8)
  • Gateway versions: 1.1.0 (patched), 1.2.0 and latest (main-59dcd51)
Dominant language
Go
Stars
85
Forks
137
Avg merge
1d 12h
Merged PRs (30d)
247

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wso2/api-platform

All issues in wso2/api-platform

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.