Skip to content

Commit

Permalink
security updates
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Aug 22, 2024
1 parent 7935476 commit 8d432b7
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 25 deletions.
16 changes: 8 additions & 8 deletions lib/metanorma/standoc/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def document1(node)

def insert_xml_cr(doc)
doc.gsub(%r{(</(clause|table|figure|p|bibitem|ul|ol|dl|dt|dd|li|example|
sourcecode|formula|quote|references|annex|appendix|title|
name|note|thead|tbody|tfoot|th|td|form|requirement|
recommendation|permission|imagemap|svgmap|preferred|
admitted|related|deprecates|letter-symbol|domain|
graphical-symbol|expression|abbreviation-type|subject|
pronunciation|grammar|term|terms|termnote|termexample|
termsource|origin|termref|modification)>)}x, "\\1\n")
sourcecode|formula|quote|references|annex|appendix|title|name|note|
thead|tbody|tfoot|th|td|form|requirement|recommendation|permission|
imagemap|svgmap|preferred|admitted|related|domain|deprecates|
letter-symbol|graphical-symbol|expression|subject|abbreviation-type|
pronunciation|grammar|term|terms|termnote|termexample|termsource|
origin|termref|modification)>)}x, "\\1\n")
.gsub(%r{(<(title|name))}, "\n\\1")
.gsub(%r{(<sourcecode[^>]*>)\s+(<name[^>]*>[^<]+</name>)\s+}, "\\1\\2")
.gsub(%r{(<sourcecode[^<>]*>)\s+(<name[^<>]*>[^<]+</name>)\s+},
"\\1\\2")
end

def version
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/cleanup_inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def related_cleanup(xmldoc)
def key_extract_locality(elem)
elem["key"].include?(",") or return
elem.add_child("<locality>#{elem['key'].sub(/^[^,]+,/, '')}</locality>")
elem["key"] = elem["key"].sub(/,.*$/, "")
elem["key"] = elem["key"].sub(/(^[^,]+),.*$/, "\\1")
end

def concept_termbase_cleanup(elem)
Expand Down
4 changes: 2 additions & 2 deletions lib/metanorma/standoc/cleanup_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Metanorma
module Standoc
module Cleanup
def textcleanup(result)
text = result.flatten.map { |l| l.sub(/\s*\Z/, "") } * "\n"
text = text.gsub(/\s+<fn /, "<fn ")
text = result.flatten.map { |l| l.sub(/(?<!\s)\s*\Z/, "") } * "\n"

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
text = text.gsub(/(?<!\s)\s+<fn /, "<fn ")

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
%w(passthrough passthrough-inline).each do |v|
text.gsub!(%r{<#{v}\s+formats="metanorma">([^<]*)
</#{v}>}mx) { @c.decode($1) }
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/datamodel/plantuml_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(yml, plantuml_path)
end

def join_as_plantuml(*ary)
ary.compact.join("\n").sub(/\s+\Z/, "")
ary.compact.join("\n").sub(/(?<!\s)\s+\Z/, "")

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
end

def render
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/localbib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def read_files(node)

def init_file_bibdb_config(defn, key)
/=/.match?(defn) or defn = "file=#{defn}"
values = defn.split(",").map { |item| item.split /\s*=\s*/ }.to_h
values = defn.split(",").map { |item| item.split /(?<!\s)\s*=\s*/ }.to_h

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
values["key"] = key
values["format"] ||= "bibtex" # all we currently suppoort
values
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PseudocodeBlockMacro < Asciidoctor::Extensions::BlockProcessor
on_context :example, :sourcecode

def init_indent(line)
/^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ line
/^(?<prefix>[ \t]*)(?![ \t])(?<suffix>.*)$/ =~ line

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of '\t'.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of '\t'.
prefix = prefix.gsub("\t", "\u00a0\u00a0\u00a0\u00a0")
.tr(" ", "\u00a0")
prefix + suffix
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/macros_plantuml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def self.save_plantuml(_parent, reader, _localdir)

def self.prep_source(reader)
src = reader.source
reader.lines.first.sub(/\s+$/, "").match /^@startuml($| )/ or
reader.lines.first.sub(/(?<!\s)\s+$/, "").match /^@startuml($| )/ or

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
src = "@startuml\n#{src}\n@enduml\n"
%r{@enduml\s*$}m.match?(src) or
raise "@startuml without matching @enduml in PlantUML!"
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Metanorma
module Standoc
module Refs
def iso_publisher(bib, code)
code.sub(/ .*$/, "").split("/").each do |abbrev|
code.sub(/(?<! ) .*$/, "").split("/").each do |abbrev|

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings starting with ' ' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with ' ' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with ' ' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with ' ' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with ' ' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with ' ' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with ' ' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with ' ' and with many repetitions of ' '.
bib.contributor do |c|
c.role type: "publisher"
c.organization do |org|
Expand Down
13 changes: 7 additions & 6 deletions lib/metanorma/standoc/ref_utility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def id_and_year(id, year)
def norm_year(year)
/^&\#821[12];$/.match(year) and return "--"
/^\d\d\d\d-\d\d\d\d$/.match(year) and return year
year&.sub(/(?<=[0-9])-.*$/, "")
year&.sub(/^([0-9]+)-.*$/, "\\1")
end

def conditional_date(bib, match, noyr)
Expand All @@ -46,7 +46,7 @@ def docid(bib, code)
@bibdb&.docid_type(code) || [nil, code]
end
code1.sub!(/^nofetch\((.+)\)$/, "\\1")
bib.docidentifier **attr_code(type: type) do |d|
bib.docidentifier **attr_code(type:) do |d|
d << code1
end
end
Expand All @@ -59,15 +59,16 @@ def docnumber(bib, code)
end

def mn_code(code)
code.sub(/^\(/, "[").sub(/\).*$/, "]")
code.sub(/^\(/, "[").sub(/^([^)]+)\).*$/, "\\1]")
.sub(/^dropid\((.+)\)$/, "\\1")
.sub(/^hidden\((.+)\)$/, "\\1")
.sub(/^nofetch\((.+)\)$/, "\\1")
.sub(/^local-file\((.+)\)$/, "\\1")
end

def analyse_ref_localfile(ret)
m = /^local-file\((?:(?<source>[^,]+),\s*)?(?<id>.+)\)$/.match(ret[:id])
m = /^local-file\((?:(?<source>[^,)]+),\s*)?(?<id>[^)]+)\)$/
.match(ret[:id])

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'local-file(' and with many repetitions of ' '.
m or return ret
ret.merge(id: m[:id], localfile: m[:source] || "default")
end
Expand All @@ -88,15 +89,15 @@ def analyse_ref_dropid(ret)
end

def analyse_ref_repo_path(ret)
m = /^(?<type>repo|path|attachment):\((?<key>[^,]+),?(?<id>[^)]*)\)$/
m = /^(?<type>repo|path|attachment):\((?<key>[^,)]+),?(?<id>[^)]*)\)$/
.match(ret[:id]) or return ret

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'repo:((' and with many repetitions of '(('.
id = if m[:id].empty?
if m[:type] == "attachment"
"(#{m[:key]})"
else m[:key].sub(%r{^[^/]+/}, "")
end
else m[:id] end
ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
ret.merge(id:, type: m[:type], key: m[:key], nofetch: true)
end

def analyse_ref_numeric(ret)
Expand Down
4 changes: 2 additions & 2 deletions lib/metanorma/standoc/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def sectiontype1(node)
node.attr("heading")&.downcase ||
node.title
.gsub(%r{<index>.*?</index>}m, "")
.gsub(%r{<fn[^>]*>.*?</fn>}m, "")
.gsub(/<[^>]+>/, "")
.gsub(%r{<fn[^<>]*>.*?</fn>}m, "")
.gsub(/<[^<>]+>/, "")

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.
.strip.downcase.sub(/\.$/, "")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/metanorma/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@
:scripts: spec/assets/scripts.html
INPUT
html = File.read("test.html", encoding: "utf-8")
expect(html).to match(%r{<script>})
expect(html).to match(%r{<script>}i)
end

it "uses specified fonts and assets in HTML" do
Expand Down

0 comments on commit 8d432b7

Please sign in to comment.