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

Add the ability to provide parameters via urlencoded form #5935

Closed
wants to merge 2 commits into from

Conversation

jefferai
Copy link
Member

@jefferai jefferai commented Dec 11, 2018

Prereq for some things coming later (maybe)

Makes using curl way nicer

Additionally, adds the ability to disable TLS for test clusters

Prereq for some things coming later

Additionally, adds the ability to disable TLS for test clusters
@jefferai jefferai added this to the 1.1 milestone Dec 11, 2018

// First attempt to get form parameters; if none exist, read the body and
// parse as JSON
err := r.ParseForm()
Copy link
Contributor

Choose a reason for hiding this comment

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

This parsing will not have the max_request_size limiter imposed. Is that something you'd want to put at the start, applicable to both parsing paths?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's true. I guess I should put it behind that, it just makes things a bit more complicated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@kalafut
Copy link
Contributor

kalafut commented Dec 11, 2018

I believe this will cause surprises for curl and possibly other users. The default content-type curl for JSON data will be application/x-www-form-urlencoded. I confirmed that this command no longer works:

curl \
    --header "X-Vault-Token: root" \
    --request POST \
    --data @payload.json \
    http://127.0.0.1:8200/v1/secret/data/my-secret
{"errors":["no data provided"]}

Instead you have to do:

curl \
    --header "X-Vault-Token: root" --header "Content-Type: application/json"
    --request POST \
    --data @payload.json \
    http://127.0.0.1:8200/v1/secret/data/my-secret

In the first case, the data is getting parsed as a form with key="[payload.json contents]" value="".

@jefferai
Copy link
Member Author

That may be a totally acceptable tradeoff. You can use --data-binary instead with curl which should work.

@briankassouf
Copy link
Contributor

@jefferai I worry this change would break backwards compatibility for scripts/applications, thoughts?

@jefferai
Copy link
Member Author

Sure, which is why we should probably not merge this yet.

@jefferai
Copy link
Member Author

Stupid question. What if we just check the first character to see if it's {? Things that take bodies that are JSON are always JSON objects, AFAIK. So if the first byte is that, we expect JSON, otherwise, trust whatever content-type.

@jefferai jefferai modified the milestones: 1.1, not-scheduled Feb 19, 2019
@kalafut
Copy link
Contributor

kalafut commented May 10, 2019

I think an initial classification of "this looks like it's intended to be JSON, so assume it is" could work. The criteria should probably be something like (as regex): ^\s*[[{]

@jefferai
Copy link
Member Author

All input to Vault is specified as part of a map -- as far as I can recall -- so I think really it would be just checking whether the first rune is {.

@kalafut
Copy link
Contributor

kalafut commented May 13, 2019

Yeah, an array input doesn't seem too likely. I think leading whitespace is still something to be considered, however. It's valid JSON and could easily be present, whether via some client or just an errant leading space in a script.

@chrishoffman
Copy link
Contributor

Closing this for now. We can reopen or create a new PR if we still want to go this route.

kalafut pushed a commit that referenced this pull request Feb 10, 2020
The approach taken is intended to be conservative since we've always
assumed JSON and not required Content-Type. Tools and libraries that
default to "application/x-www-form-urlencoded" even when JSON is being
sent (e.g. curl) will break without these extra backwards compatibility
measures.

This PR is a reboot of: #5935
@pbernal pbernal removed this from the not-scheduled milestone May 26, 2020
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.

5 participants