validate property, parameter and recur names in from_jcal#1466
Conversation
jcal names were emitted raw into the content line, so a `:`/`;` or a lone carriage return in a name could inject parameters or a new line. run them through validate_token at parse time like from_ical does.
| JCalParsingError.validate_property(prop, cls, path=[1, i]) | ||
| prop_name = prop[0] | ||
| try: | ||
| validate_token(prop_name) |
There was a problem hiding this comment.
Validation can be even stricter since RFC 7265 3.3 requires lower case. Havent checked usage of JCalParsingError.validate_property but maybe the validation can be moved there?
There was a problem hiding this comment.
Added a lower-case check after the token check here. I looked at folding it into validate_property, but that only sees the property list (not parameter names or RRULE part names), and vRecur.from_jcal calls it on the rrule property itself rather than the part keys, so I kept the check at each of the three parse sites to keep the messages specific. One small thing: property names are 3.4, 3.3 is components, so I cited 3.4 in the news entry.
| "All parameter names must be strings.", cls, value=name | ||
| ) | ||
| try: | ||
| validate_token(name) |
There was a problem hiding this comment.
name must also be lower case as per section 3.5
There was a problem hiding this comment.
Done, name now has to be lower case here too, otherwise it raises JCalParsingError. 3.5 was right.
| recur = {} | ||
| for key, value in jcal_property[3].items(): | ||
| try: | ||
| validate_token(key) |
There was a problem hiding this comment.
Done, same lower-case check on the part name. 3.6.10 was right.
|
Nice work. I checked the lower case part and linked the sections. Hope I did not make a mistake. Can you please add the lower case validation as well? |
rfc 7265 lowercases names (sections 3.4, 3.5, 3.6.10), so reject any that are not lower case after the token check.
dae5a8a to
3d047ac
Compare
|
Pushed the lower-case validation for all three names, with tests and an updated news entry. A few existing recur tests passed upper-case keys like |
Linked issue
No separate issue; reported and fixed here.
Description
Repro: convert untrusted jCal where a property name, parameter name or
RRULEpart name carries a lone\r(or a:/;) into iCalendar, for example viaCalendar.from_jcal(jcal).to_ical().Cause:
Component.from_jcal,Parameters.from_jcalandvRecur.from_jcalkeep the jCal name verbatim and emit it raw into the content line, whereasParameters.from_icalalready runs names throughvalidate_token. A:or;rewrites the property or parameter structure on the same line; a lone\rslips past the\n-only assert inContentlineand turns up as a new content line for consumers that treat a bare carriage return as a break.Fix: run each jCal name through
validate_tokenat parse time, raisingJCalParsingErrorfor names that are not valid iCalendar tokens.Checklist
/news, following the instructions in Change log entry format.📚 Documentation preview 📚: https://icalendar--1466.org.readthedocs.build/en/1466/