-
Notifications
You must be signed in to change notification settings - Fork 203
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
Custom feed path setting #54
Conversation
@@ -12,6 +12,10 @@ def config | |||
@context.registers[:site].config | |||
end | |||
|
|||
def path | |||
config["feed_path"] || "feed.xml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to use Jekyll.sanitized_path(@site.source, (config["feed_path"] || "feed.xml"))
here. A malicious user could provide a relative path outside the Jekyll site source to expose the contents of files they otherwise wouldn't have access to. It may also be worth adding a test for this (e.g., verify a path of ../../foo
becomes /foo
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually the case? This path
is only used as a string in the link
tag rendered into the pages, it doesn't read the file at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh. I was thinking the source template. We sanitize prior to the output destination (to prevent overwriting a file outside the site source).
@parkr is there any problem with it being passed into keep_files
? Should we sanitize there to be safe?
Thanks for the pull request @orderedlist. Small doc suggestion, and small security fix, otherwise, this 👀 good. |
:) |
@@ -12,6 +12,14 @@ def config | |||
@context.registers[:site].config | |||
end | |||
|
|||
def path | |||
if config["feed"] && config["feed"]["path"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this blow up if someone does feed: foo
in their config file? In that case config["feed"]
won't be a dict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goot catch. Here's how we did it for jemoji:
def src
@src ||=
if config.key?("emoji") && config["emoji"].key?("src")
config["emoji"]["src"]
else
"https://assets.github.com/images/icons/"
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't key?
have the same problem? There's no String#key?
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps
def path
if config.key?("feed")
if config["feed"].is_a? Hash
config["feed"]["path"]
else
config["feed"].to_s
end
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing that matters here is if this is supposed to be a hash, if it is then let it blow up because that's your fault and it's the right thing to do, if accepts any value then this matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, if the goal is only to support feed
as a hash then blowing up might be a good thing. I don't know the conventions around this kind of thing in Jekyll-land which is why I raised it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not up to Jekyll-Core it's up to the author of the plugin or in this case @orderedlist, if he wants a hash then that's on him tbh, Jekyll doesn't enforce like that (not that I've seen at least,) so it's entirely up to the author if he wants to blow up because he wants a hash or not, it's not up to Jekyll-Core whether he accepts both gracefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the way it is now:
if config["feed"] && config["feed"]["path"]
...won't blow up unless feed.path is set and incorrect (e.g. a hash instead of a string). I'm personally fine with this, as it's well documented how it should properly be configured.
This is broken on 3.0, is this going to be fixed because we have a lot of users on 3.0 and this is a defacto-plugin since it sits under the Jekyll umbrella. |
Can you explain what you mean by that? |
Actually, this failing test confuses me based on the way it's failing, I'm going to patch a local version and drop myself into a debugger and check out the state machine across all Jekyll versions because logically if it failed on one it should fail on all no? |
I finally had a second to look at the tests to figure out what was going on and it turns out that the site wasn't regenerating on Jekyll 3 so it wasn't picking up what @orderedlist wanted but I also had to make another small change to the source to get the test to pass: let(:config) do
Jekyll.configuration(Jekyll::Utils.deep_merge_hashes(
overrides, {
"feed" => {
"path" => "atom.xml"
}
}
))
end That way the new config would pick up the original overrides with regeneration. |
Start the fix to failing test in #54.
I think I've addressed all the feedback. 👾 |
Because dumb.
Is there any issue with adding an unsanitized, potentially relative or synmlink path to keep files? @parkr? |
The path is sanitized later, I thought? |
@orderedlist thanks for submitting the PR and for working through the feedback. WIll try to get a new release out so you can test it out in the wild. 😸 |
❤️ |
@orderedlist that gif tho. 😂 👍 |
Many sites already have feeds setup at a path other than
feed.xml
. If their host e.g., GitHub pages, doesn’t allow for redirects, changing to a new feed path isn’t really an option.This PR adds a
_config.yml
option offeed_path
, which defaults tofeed.xml
but can be set to a custom path likeatom.xml
.