synapse 2.201.0__py311-none-any.whl → 2.203.0__py311-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of synapse might be problematic. Click here for more details.

Files changed (106) hide show
  1. synapse/axon.py +4 -4
  2. synapse/cmds/cortex.py +4 -6
  3. synapse/cmds/hive.py +10 -10
  4. synapse/common.py +17 -58
  5. synapse/cortex.py +36 -29
  6. synapse/data/__init__.py +3 -2
  7. synapse/data/iana.uris.mpk +1 -0
  8. synapse/lib/autodoc.py +3 -3
  9. synapse/lib/base.py +2 -12
  10. synapse/lib/cell.py +9 -13
  11. synapse/lib/cli.py +2 -2
  12. synapse/lib/config.py +2 -2
  13. synapse/lib/encoding.py +4 -3
  14. synapse/lib/httpapi.py +7 -11
  15. synapse/lib/json.py +224 -0
  16. synapse/lib/lmdbslab.py +1 -1
  17. synapse/lib/oauth.py +176 -54
  18. synapse/lib/parser.py +2 -1
  19. synapse/lib/rstorm.py +18 -14
  20. synapse/lib/schemas.py +87 -1
  21. synapse/lib/scrape.py +35 -13
  22. synapse/lib/snap.py +2 -1
  23. synapse/lib/storm.lark +5 -4
  24. synapse/lib/storm.py +2 -2
  25. synapse/lib/storm_format.py +2 -1
  26. synapse/lib/stormhttp.py +11 -13
  27. synapse/lib/stormlib/aha.py +4 -4
  28. synapse/lib/stormlib/auth.py +1 -1
  29. synapse/lib/stormlib/cache.py +2 -2
  30. synapse/lib/stormlib/cortex.py +5 -5
  31. synapse/lib/stormlib/graph.py +1 -1
  32. synapse/lib/stormlib/imap.py +1 -1
  33. synapse/lib/stormlib/json.py +8 -11
  34. synapse/lib/stormlib/model.py +1 -1
  35. synapse/lib/stormlib/notifications.py +2 -2
  36. synapse/lib/stormlib/oauth.py +105 -2
  37. synapse/lib/stormlib/stats.py +4 -0
  38. synapse/lib/stormlib/stix.py +3 -4
  39. synapse/lib/stormlib/vault.py +6 -6
  40. synapse/lib/stormlib/xml.py +2 -2
  41. synapse/lib/stormtypes.py +19 -28
  42. synapse/lib/structlog.py +3 -3
  43. synapse/lib/types.py +2 -1
  44. synapse/lib/version.py +2 -2
  45. synapse/lib/view.py +7 -3
  46. synapse/models/base.py +51 -2
  47. synapse/telepath.py +79 -18
  48. synapse/tests/files/__init__.py +0 -1
  49. synapse/tests/test_axon.py +1 -1
  50. synapse/tests/test_cmds_cortex.py +3 -2
  51. synapse/tests/test_cmds_hive.py +4 -4
  52. synapse/tests/test_common.py +29 -19
  53. synapse/tests/test_cortex.py +28 -8
  54. synapse/tests/test_lib_ast.py +3 -3
  55. synapse/tests/test_lib_autodoc.py +5 -5
  56. synapse/tests/test_lib_base.py +1 -1
  57. synapse/tests/test_lib_cell.py +24 -7
  58. synapse/tests/test_lib_config.py +2 -2
  59. synapse/tests/test_lib_encoding.py +2 -2
  60. synapse/tests/test_lib_grammar.py +68 -64
  61. synapse/tests/test_lib_httpapi.py +13 -13
  62. synapse/tests/test_lib_json.py +219 -0
  63. synapse/tests/test_lib_multislabseqn.py +2 -1
  64. synapse/tests/test_lib_node.py +2 -2
  65. synapse/tests/test_lib_scrape.py +50 -0
  66. synapse/tests/test_lib_storm.py +12 -6
  67. synapse/tests/test_lib_stormhttp.py +4 -4
  68. synapse/tests/test_lib_stormlib_auth.py +3 -2
  69. synapse/tests/test_lib_stormlib_cortex.py +10 -12
  70. synapse/tests/test_lib_stormlib_infosec.py +2 -3
  71. synapse/tests/test_lib_stormlib_json.py +18 -21
  72. synapse/tests/test_lib_stormlib_log.py +1 -1
  73. synapse/tests/test_lib_stormlib_oauth.py +603 -1
  74. synapse/tests/test_lib_stormlib_stats.py +13 -3
  75. synapse/tests/test_lib_stormlib_stix.py +5 -5
  76. synapse/tests/test_lib_stormtypes.py +4 -4
  77. synapse/tests/test_lib_structlog.py +5 -6
  78. synapse/tests/test_lib_view.py +8 -0
  79. synapse/tests/test_model_base.py +32 -0
  80. synapse/tests/test_model_infotech.py +2 -2
  81. synapse/tests/test_telepath.py +56 -35
  82. synapse/tests/test_tools_cryo_cat.py +4 -3
  83. synapse/tests/test_tools_docker_validate.py +4 -2
  84. synapse/tests/test_tools_feed.py +30 -2
  85. synapse/tests/test_tools_genpkg.py +1 -1
  86. synapse/tests/test_tools_healthcheck.py +8 -7
  87. synapse/tests/test_utils.py +2 -2
  88. synapse/tests/test_utils_getrefs.py +35 -28
  89. synapse/tests/utils.py +3 -3
  90. synapse/tools/autodoc.py +3 -3
  91. synapse/tools/changelog.py +2 -2
  92. synapse/tools/cryo/cat.py +3 -3
  93. synapse/tools/csvtool.py +2 -3
  94. synapse/tools/docker/validate.py +5 -5
  95. synapse/tools/feed.py +2 -1
  96. synapse/tools/genpkg.py +3 -2
  97. synapse/tools/healthcheck.py +2 -3
  98. synapse/tools/json2mpk.py +2 -2
  99. synapse/utils/getrefs.py +10 -8
  100. synapse/vendor/cpython/lib/json.py +35 -0
  101. synapse/vendor/cpython/lib/test/test_json.py +22 -0
  102. {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/METADATA +2 -1
  103. {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/RECORD +106 -101
  104. {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/WHEEL +1 -1
  105. {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/LICENSE +0 -0
  106. {synapse-2.201.0.dist-info → synapse-2.203.0.dist-info}/top_level.txt +0 -0
synapse/tests/utils.py CHANGED
@@ -21,13 +21,11 @@ import io
21
21
  import os
22
22
  import sys
23
23
  import copy
24
- import json
25
24
  import math
26
25
  import types
27
26
  import shutil
28
27
  import typing
29
28
  import asyncio
30
- import hashlib
31
29
  import inspect
32
30
  import logging
33
31
  import tempfile
@@ -59,6 +57,7 @@ import synapse.lib.cell as s_cell
59
57
  import synapse.lib.coro as s_coro
60
58
  import synapse.lib.cmdr as s_cmdr
61
59
  import synapse.lib.hive as s_hive
60
+ import synapse.lib.json as s_json
62
61
  import synapse.lib.task as s_task
63
62
  import synapse.lib.const as s_const
64
63
  import synapse.lib.layer as s_layer
@@ -101,7 +100,7 @@ def deguidify(x):
101
100
 
102
101
  def jsonlines(text: str):
103
102
  lines = [k for k in text.split('\n') if k]
104
- return [json.loads(line) for line in lines]
103
+ return [s_json.loads(line) for line in lines]
105
104
 
106
105
  async def waitForBehold(core, events):
107
106
  async for mesg in core.behold():
@@ -457,6 +456,7 @@ testmodel = {
457
456
  ('tick', ('test:time', {}), {}),
458
457
  ('hehe', ('str', {}), {}),
459
458
  ('ndefs', ('array', {'type': 'ndef'}), {}),
459
+ ('somestr', ('test:str', {}), {}),
460
460
  )),
461
461
 
462
462
  ('test:migr', {}, (
synapse/tools/autodoc.py CHANGED
@@ -1,6 +1,5 @@
1
1
  import sys
2
2
  import copy
3
- import json
4
3
  import asyncio
5
4
  import logging
6
5
  import argparse
@@ -13,6 +12,7 @@ import synapse.common as s_common
13
12
  import synapse.cortex as s_cortex
14
13
  import synapse.telepath as s_telepath
15
14
 
15
+ import synapse.lib.json as s_json
16
16
  import synapse.lib.storm as s_storm
17
17
  import synapse.lib.config as s_config
18
18
  import synapse.lib.output as s_output
@@ -262,7 +262,7 @@ def processTypes(rst, dochelp, types):
262
262
  rst.addLines(f' * {key}: ``{valu}``')
263
263
  continue
264
264
  lines = [f' * {key}:\n', ' ::\n\n']
265
- json_lines = json.dumps(valu, indent=1, sort_keys=True)
265
+ json_lines = s_json.dumps(valu, indent=True, sort_keys=True).decode()
266
266
  json_lines = [' ' + line for line in json_lines.split('\n')]
267
267
  lines.extend(json_lines)
268
268
  lines.append('\n')
@@ -810,7 +810,7 @@ async def docConfdefs(ctor):
810
810
  data = {k: v for k, v in conf.items() if k not in (
811
811
  'description', 'default', 'type', 'hideconf', 'hidecmdl',
812
812
  )}
813
- parts = json.dumps(data, sort_keys=True, indent=2).split('\n')
813
+ parts = s_json.dumps(data, sort_keys=True, indent=True).decode().split('\n')
814
814
  lines.append(' ::')
815
815
  lines.append('\n')
816
816
  lines.extend([f' {p}' for p in parts])
@@ -476,7 +476,7 @@ async def gen(opts: argparse.Namespace,
476
476
  if opts.verbose:
477
477
  outp.printf('Validating data against schema')
478
478
 
479
- s_schemas._reqChanglogSchema(data)
479
+ s_schemas._reqChangelogSchema(data)
480
480
 
481
481
  if opts.verbose:
482
482
  outp.printf('Saving the following information:')
@@ -835,7 +835,7 @@ async def format(opts: argparse.Namespace,
835
835
 
836
836
  files_processed.append(fp)
837
837
 
838
- s_schemas._reqChanglogSchema(data)
838
+ s_schemas._reqChangelogSchema(data)
839
839
 
840
840
  data.setdefault('prs', [])
841
841
  prs = data.get('prs')
synapse/tools/cryo/cat.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import sys
2
- import json
3
2
  import pprint
4
3
  import asyncio
5
4
  import argparse
@@ -7,6 +6,7 @@ import logging
7
6
 
8
7
  import synapse.telepath as s_telepath
9
8
 
9
+ import synapse.lib.json as s_json
10
10
  import synapse.lib.output as s_output
11
11
  import synapse.lib.msgpack as s_msgpack
12
12
 
@@ -50,14 +50,14 @@ async def main(argv, outp=s_output.stdout):
50
50
  await tank.puts(items)
51
51
  return 0
52
52
 
53
- items = [json.loads(line) for line in sys.stdin]
53
+ items = [s_json.loads(line) for line in sys.stdin]
54
54
  await tank.puts(items)
55
55
  return 0
56
56
 
57
57
  async for item in tank.slice(opts.offset, opts.size):
58
58
 
59
59
  if opts.jsonl:
60
- outp.printf(json.dumps(item[1], sort_keys=True))
60
+ outp.printf(s_json.dumps(item[1], sort_keys=True).decode())
61
61
 
62
62
  elif opts.msgpack:
63
63
  sys.stdout.buffer.write(s_msgpack.en(item[1]))
synapse/tools/csvtool.py CHANGED
@@ -1,6 +1,5 @@
1
1
  import csv
2
2
  import sys
3
- import json
4
3
  import asyncio
5
4
  import contextlib
6
5
 
@@ -12,6 +11,7 @@ import synapse.telepath as s_telepath
12
11
  import synapse.lib.cmd as s_cmd
13
12
  import synapse.lib.base as s_base
14
13
  import synapse.lib.cmdr as s_cmdr
14
+ import synapse.lib.json as s_json
15
15
  import synapse.lib.output as s_output
16
16
  import synapse.lib.version as s_version
17
17
 
@@ -114,8 +114,7 @@ async def runCsvImport(opts, outp, text, stormopts):
114
114
  outp.printf(repr(mesg))
115
115
 
116
116
  if logfd is not None:
117
- byts = json.dumps(mesg).encode('utf8')
118
- logfd.write(byts + b'\n')
117
+ logfd.write(s_json.dumps(mesg, newline=True))
119
118
 
120
119
  if opts.cli:
121
120
  await s_cmdr.runItemCmdr(core, outp, True)
@@ -1,7 +1,6 @@
1
1
  import os
2
2
  import re
3
3
  import sys
4
- import json
5
4
  import base64
6
5
  import pprint
7
6
  import argparse
@@ -11,6 +10,7 @@ import synapse.exc as s_exc
11
10
  import synapse.data as s_data
12
11
  import synapse.common as s_common
13
12
 
13
+ import synapse.lib.json as s_json
14
14
  import synapse.lib.output as s_outp
15
15
  import synapse.lib.certdir as s_certdir
16
16
 
@@ -50,8 +50,8 @@ def getCosignSignature(outp, image):
50
50
 
51
51
  blob = proc.stdout
52
52
  try:
53
- sigd = json.loads(blob)
54
- except json.JSONDecodeError as e:
53
+ sigd = s_json.loads(blob)
54
+ except s_exc.BadJsonText as e:
55
55
  outp.printf(f'Error decoding blob: {blob}: {e}')
56
56
  return None
57
57
  if not isinstance(sigd, dict):
@@ -104,8 +104,8 @@ def checkCosignSignature(outp, pubk_byts, image_to_verify):
104
104
  except subprocess.CalledProcessError as e: # pragma: no cover
105
105
  outp.printf(f'Error calling {" ".join(args)}: {e}')
106
106
  return None
107
- blob = json.loads(proc.stdout.decode())
108
- outp.printf(f'Cosign output:')
107
+ blob = s_json.loads(proc.stdout)
108
+ outp.printf('Cosign output:')
109
109
  outp.printf(pprint.pformat(blob))
110
110
  return True
111
111
 
synapse/tools/feed.py CHANGED
@@ -11,6 +11,7 @@ import synapse.cortex as s_cortex
11
11
  import synapse.telepath as s_telepath
12
12
 
13
13
  import synapse.lib.cmdr as s_cmdr
14
+ import synapse.lib.json as s_json
14
15
  import synapse.lib.output as s_output
15
16
  import synapse.lib.msgpack as s_msgpack
16
17
  import synapse.lib.version as s_version
@@ -24,7 +25,7 @@ def getItems(*paths):
24
25
  items = []
25
26
  for path in paths:
26
27
  if path.endswith('.json'):
27
- item = s_common.jsload(path)
28
+ item = s_json.jsload(path)
28
29
  if not isinstance(item, list):
29
30
  item = [item]
30
31
  items.append((path, item))
synapse/tools/genpkg.py CHANGED
@@ -12,6 +12,7 @@ import synapse.exc as s_exc
12
12
  import synapse.common as s_common
13
13
  import synapse.telepath as s_telepath
14
14
 
15
+ import synapse.lib.json as s_json
15
16
  import synapse.lib.output as s_output
16
17
  import synapse.lib.certdir as s_certdir
17
18
  import synapse.lib.dyndeps as s_dyndeps
@@ -224,7 +225,7 @@ def loadPkgProto(path, opticdir=None, no_docs=False, readonly=False):
224
225
  s_schemas.reqValidPkgdef(pkgdef)
225
226
 
226
227
  # Ensure the package is json safe and tuplify it.
227
- s_common.reqJsonSafeStrict(pkgdef)
228
+ s_json.reqjsonsafe(pkgdef, strict=True)
228
229
  pkgdef = s_common.tuplify(pkgdef)
229
230
  return pkgdef
230
231
 
@@ -286,7 +287,7 @@ async def main(argv, outp=s_output.stdout):
286
287
  return 1
287
288
 
288
289
  if opts.save:
289
- s_common.jssave(pkgdef, opts.save)
290
+ s_json.jssave(pkgdef, opts.save)
290
291
 
291
292
  if opts.push:
292
293
 
@@ -1,5 +1,4 @@
1
1
  import sys
2
- import json
3
2
  import socket
4
3
  import asyncio
5
4
 
@@ -8,13 +7,13 @@ import synapse.common as s_common
8
7
  import synapse.telepath as s_telepath
9
8
 
10
9
  import synapse.lib.cmd as s_cmd
10
+ import synapse.lib.json as s_json
11
11
  import synapse.lib.output as s_output
12
12
  import synapse.lib.health as s_health
13
13
  import synapse.lib.urlhelp as s_urlhelp
14
14
 
15
15
  def serialize(ret):
16
- s = json.dumps(ret, separators=(',', ':'))
17
- return s
16
+ return s_json.dumps(ret).decode()
18
17
 
19
18
  def format_component(e, mesg: str) -> dict:
20
19
  d = {
synapse/tools/json2mpk.py CHANGED
@@ -1,8 +1,8 @@
1
1
  import os
2
2
  import sys
3
- import json
4
3
  import argparse
5
4
 
5
+ import synapse.lib.json as s_json
6
6
  import synapse.lib.output as s_output
7
7
  import synapse.lib.msgpack as s_msgpack
8
8
 
@@ -37,7 +37,7 @@ def main(argv, outp=None):
37
37
  with open(path, 'r', encoding='utf8') as fd:
38
38
  with open(newp, 'wb') as pk:
39
39
  for line in fd:
40
- item = json.loads(line)
40
+ item = s_json.loads(line)
41
41
  pk.write(s_msgpack.en(item))
42
42
 
43
43
  if opts.rm:
synapse/utils/getrefs.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import sys
2
- import json
3
2
  import urllib
4
3
  import asyncio
5
4
  import logging
@@ -12,10 +11,13 @@ import synapse.exc as s_exc
12
11
  import synapse.data as s_data
13
12
  import synapse.common as s_common
14
13
 
14
+ import synapse.lib.json as s_json
15
15
  import synapse.lib.config as s_config
16
16
 
17
17
  logger = logging.getLogger(__name__)
18
18
 
19
+ BASEDIR = s_data.path('jsonschemas')
20
+
19
21
  def download_refs_handler(uri):
20
22
  '''
21
23
  This function downloads the JSON schema at the given URI, parses the given
@@ -34,18 +36,18 @@ async def _download_refs_handler(uri):
34
36
  except ValueError:
35
37
  raise s_exc.BadUrl(mesg=f'Malformed URI: {uri}.') from None
36
38
 
37
- filename = s_data.path('jsonschemas', parts.hostname, *parts.path.split('/'))
39
+ filename = s_common.genpath(BASEDIR, parts.hostname, *parts.path.split('/'))
38
40
  filepath = pathlib.Path(filename)
39
41
 
40
42
  # Check for path traversal. Unlikely, but still check
41
- if not str(filepath.absolute()).startswith(s_data.path('jsonschemas')):
43
+ if not str(filepath.absolute()).startswith(BASEDIR):
42
44
  raise s_exc.BadArg(mesg=f'Path traversal in schema URL: {uri} ?')
43
45
 
44
46
  # If we already have the file, return it
45
47
  if filepath.exists():
46
48
  logger.info(f'Schema {uri} already exists in local cache, skipping.')
47
49
  with filepath.open() as fp:
48
- return json.load(fp)
50
+ return s_json.load(fp)
49
51
 
50
52
  # Create parent directory structure if it doesn't already exist
51
53
  filepath.parent.mkdir(parents=True, exist_ok=True)
@@ -57,11 +59,11 @@ async def _download_refs_handler(uri):
57
59
  resp.raise_for_status()
58
60
  buf = await resp.read()
59
61
 
60
- data = json.loads(buf.decode())
62
+ data = s_json.loads(buf)
61
63
 
62
64
  # Save the json schema to disk
63
- with filepath.open('w') as fp:
64
- json.dump(data, fp, indent=2)
65
+ with filepath.open('wb') as fp:
66
+ s_json.dump(data, fp, indent=True)
65
67
 
66
68
  # Return the schema to satisfy fastjsonschema
67
69
  return data
@@ -76,7 +78,7 @@ def download_refs(schema):
76
78
 
77
79
  def main(argv):
78
80
  with argv.schema.open() as fp:
79
- schema = json.load(fp)
81
+ schema = s_json.load(fp)
80
82
 
81
83
  download_refs(schema)
82
84
 
@@ -0,0 +1,35 @@
1
+ ##############################################################################
2
+ # Taken from the cpython 3.11 source branch after the 3.11.10 release.
3
+ ##############################################################################
4
+ import codecs
5
+
6
+ # vendored from:
7
+ # https://github.com/python/cpython/blob/v3.11.10/Lib/json/__init__.py#L244-L271
8
+ def detect_encoding(b):
9
+ bstartswith = b.startswith
10
+ if bstartswith((codecs.BOM_UTF32_BE, codecs.BOM_UTF32_LE)):
11
+ return 'utf-32'
12
+ if bstartswith((codecs.BOM_UTF16_BE, codecs.BOM_UTF16_LE)):
13
+ return 'utf-16'
14
+ if bstartswith(codecs.BOM_UTF8):
15
+ return 'utf-8-sig'
16
+
17
+ if len(b) >= 4:
18
+ if not b[0]:
19
+ # 00 00 -- -- - utf-32-be
20
+ # 00 XX -- -- - utf-16-be
21
+ return 'utf-16-be' if b[1] else 'utf-32-be'
22
+ if not b[1]:
23
+ # XX 00 00 00 - utf-32-le
24
+ # XX 00 00 XX - utf-16-le
25
+ # XX 00 XX -- - utf-16-le
26
+ return 'utf-16-le' if b[2] or b[3] else 'utf-32-le'
27
+ elif len(b) == 2:
28
+ if not b[0]:
29
+ # 00 XX - utf-16-be
30
+ return 'utf-16-be'
31
+ if not b[1]:
32
+ # XX 00 - utf-16-le
33
+ return 'utf-16-le'
34
+ # default
35
+ return 'utf-8'
@@ -0,0 +1,22 @@
1
+ # From the python source, tests/test_json/test_unicode.py does not have a
2
+ # direct test for detect_encoding. It instead tests the various encoding
3
+ # schemes in test_bytes_decode, which uses the detection in json.loads().
4
+ # Since there is not a standalone test to vendor, we have written a simple
5
+ # test on its own.
6
+
7
+ import synapse.vendor.cpython.lib.json as v_json
8
+
9
+ import synapse.vendor.utils as s_v_utils
10
+
11
+ class JsonVendorTest(s_v_utils.VendorTest):
12
+ def test_json_detect_encoding(self):
13
+
14
+ ENCODINGS = (
15
+ 'utf-8', 'utf-8-sig',
16
+ 'utf-16', 'utf-16-le', 'utf-16-be',
17
+ 'utf-32', 'utf-32-le', 'utf-32-be',
18
+ )
19
+
20
+ for encoding in ENCODINGS:
21
+ self.assertEqual(encoding, v_json.detect_encoding('a'.encode(encoding)))
22
+ self.assertEqual(encoding, v_json.detect_encoding('ab'.encode(encoding)))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: synapse
3
- Version: 2.201.0
3
+ Version: 2.203.0
4
4
  Summary: Synapse Intelligence Analysis Framework
5
5
  Author-email: The Vertex Project LLC <root@vertex.link>
6
6
  License: Apache License 2.0
@@ -50,6 +50,7 @@ Requires-Dist: idna<3.8,>=3.6
50
50
  Requires-Dist: python-dateutil<3.0,>=2.8
51
51
  Requires-Dist: pytz<2024.1,>=2023.3
52
52
  Requires-Dist: beautifulsoup4[html5lib]<5.0,>=4.11.1
53
+ Requires-Dist: orjson<4.0,>=3.10.15
53
54
  Provides-Extra: dev
54
55
  Requires-Dist: pytest<8.0.0,>=7.2.0; extra == "dev"
55
56
  Requires-Dist: autopep8<3.0.0,>=2.0.4; extra == "dev"