Skip to content

Conversation

pabs3
Copy link
Contributor

@pabs3 pabs3 commented Sep 18, 2021

Also document how -r does separators.

Reported-by: @pcworld
Reported-in: #1271 (comment)

Also update the older versions of the manual.
Also update the older versions of the manual.

Reported-by: @pcworld
Reported-in: jqlang#1271 (comment)
@pabs3 pabs3 force-pushed the document-security-issues branch from 13d29af to f65a269 Compare September 21, 2021 07:36
@pabs3
Copy link
Contributor Author

pabs3 commented Sep 21, 2021

Hmm, the AppVeyor failure seems unrelated to the changes in this PR.

Comment on lines +199 to +202
Please note a **potential security issue** when using this option.
Please note that if the selected data of the input JSON contains
newline characters then processing of jq output will incorrectly
split a single item containing an newline character into two items.
Copy link

@vdukhovni vdukhovni Oct 16, 2021

Choose a reason for hiding this comment

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

Frankly, I'm not convinced this is a security issue, for example, when CSV output is generated with @csv, multi-line output works correctly, because CSV handles multi-line strings correctly. Similar observations can be made about @html, etc.

Raw strings only have as much structure as is ensured in their construction, and there's nothing jq-specific here. If one wants structured output that won't confuse some downstream parser, one has to ensure the right encoding is used, which may or may be JSON.

Thus, if one wants to use jq as an awk or sed replacement working with line-oriented data, one can do that:

$ printf -- 'Do it with %s!\n' "sed" |
      jq -Rr 'sub("\\bsed\\b"; "jq"; "g")'
Do it with jq

$ cat /etc/passwd |  # Averaging uids from /etc/passwd is of course nonsense!
     jq -Rrn 'reduce (inputs | [limit(3;splits(":"))] | .[2] | tonumber) as $n ([0, 0]; [.[0]+$n, .[1] + 1])
              | "The average uid is: \(.[0]*1000/.[1] | rint | ./1000)"'
The average uid is: 1715.038

So what we have here is that when the output is not JSON it needs to be appropriately encoded for the syntax expected by the consumer. I don't think this really deserves any sort of security warning.

Even with JSON output, if the elements encoded as JSON are sloppily constructed, they may already mediate some sort of "injection" attack.

@pabs3
Copy link
Contributor Author

pabs3 commented Oct 17, 2021 via email

@pabs3
Copy link
Contributor Author

pabs3 commented Oct 17, 2021

It is clear that this particular PR isn't acceptable, so closing.

@pabs3 pabs3 closed this Oct 17, 2021
peter-dolkens added a commit to peter-dolkens/jq that referenced this pull request Feb 3, 2023
`--nul-output` / `-0` was removed RE: jqlang#1271 and jqlang#2350
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.

2 participants