-
Notifications
You must be signed in to change notification settings - Fork 13
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
Presence of <SVG in POSTed content results in 403 #272
Comments
As there were some oddities w.r.t. reproducing this effect by others, here the full code of the script I'm using to test. There are four pieces of content to test POSTing.
|
@tonzyl don't quote me on this but on first glance (i haven't tried the code yet), you're using the structure of the JSON post style but doing a form-urlencoded post, I'm not sure this is supported? but also:
So at the very least your |
Hi @Ruxton that only pertains to the categories in this case, right? When I tried to nest those that didn't work, but adding them as separate fields does work in this case. Without them the issue is the same though. (And without the <svg bit, the entire construct works. E.g. this https://www.zylstra.org/blog/2022/01/my-first-micropub-posting/ was posted with the script above.) I first ensured the calls work, then that the structure of the POSTed info worked, and then started playing with the actual posting content submitted which surfaced the issue. (And if you mean the content/html nesting, POSTing only works if done that way) If I switch to JSON (though I prefer form, which is also the default in the spec iirc), simply changing the headers is not enough I assume (I think I tried that earlier but then the call fails). Warning: limited coding skills here, so going by trial and error. |
Well, Also those categories look a bit ... off? Normally you'd define them like so:
Note that, IIRC, (Now, because some APIs don't like these keys and instead expect |
To encode the request body as JSON, you could probably:
Or something. That would turn
|
@janboddez , thanks for responding (here and in other channels). Micropub is spec'd such that it must work with form-urlencoded, and JSON is optional, so I am somewhat surprised by treating JSON as the default. https://www.w3.org/TR/micropub/#create Anyway, the oddity is in how content gets filtered on <svg, resulting in a 403 error. The rest works as intended and results in correct postings on the blog. |
Update: While I haven't figured out what causes the issue I started with above, I have made progress. I've converted my request to the Micropub endpoint into JSON, while still submitting it with the php file_get_contents function. Then the SVG gets accepted! I'd prefer using form-urlencode as it is the Micropub standard's default, but if this works it works. Could not get the JSON to work with curl_exec though, but that's not for here, and something to further explore on my own. To get the Micropub endpoint, using file_get_contents, to accept the JSON correctly I did have to change the way I constructed the submitted info a bit. This is what I ended up with:
@janboddez using JSON providing the categories works normally now. But I did have to package the posting's variables a bit differently in arrays to get to the right result at the micropub endpoint. Why SVG doesn't work with form-url-encode remains a mystery to me. |
I've created a basic PHP Micropub client to talk to my WordPress Micropub endpoint. It uses form-urlencoded and calls the endpoint with file_get_contents()
This works all as intended.
When I include an SVG icon in the html content however the endpoint returns a 403 error. It was pointed out to me that this might be an issue with WP core, not with the plugin ( https://core.trac.wordpress.org/ticket/30377 https://core.trac.wordpress.org/ticket/54244 ). However that seems to be about GET requests and urls, not POST requests.
Original HTML that results in 403:
'
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" width="19" height="19"><path d="M576 240c0 115-129 208-288 208-48.3 0-93.9-8.6-133.9-23.8-40.3 31.2-89.8 50.3-142.4 55.7-5.2.6-10.2-2.8-11.5-7.7-1.3-5 2.7-8.1 6.6-11.8 19.3-18.4 42.7-32.8 51.9-94.6C21.9 330.9 0 287.3 0 240 0 125.1 129 32 288 32s288 93.1 288 208z"/></svg> <em>Some text here</em>
'but pairing it down showed that
'
some text <svg></svg> more text
'also gets a 403 and even
'
some text <svg some other text
'gets a 403.
If I leave out the first < in the original html it also posts fine, it really is down to the presence of '<svg'
The text was updated successfully, but these errors were encountered: