
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
pycddl
Advanced tools
CDDL is a schema language for the CBOR serialization format.
pycddl allows you to:
cddl library.Here we use the cbor2 library to serialize a dictionary to CBOR, and then validate it:
from pycddl import Schema
import cbor2
uint_schema = Schema("""
object = {
xint: uint
}
"""
)
uint_schema.validate_cbor(cbor2.dumps({"xint", -2}))
If validation fails, a pycddl.ValidationError is raised.
You can deserialize CBOR to Python objects using cbor.loads().
However:
cbor2 uses C code by default, and the C programming language is prone to memory safety issues.
If you are reading untrusted CBOR, better to use a Rust library to decode the data.By deserializing with pycddl, you solve the first problem, and a future version of pycddl will solve the second problem (see https://gitlab.com/tahoe-lafs/pycddl/-/issues/37).
from pycddl import Schema
import cbor2
uint_schema = Schema("""
object = {
xint: uint
}
"""
)
deserialized = uint_schema.validate_cbor(cbor2.dumps({"xint", -2}), True)
assert deserialized == {"xint": -2}
If you don't care about schemas, you can just deserialize the CBOR like so:
from pycddl import Schema
ACCEPT_ANYTHING = Schema("main = any")
def loads(encoded_cbor_bytes):
return ACCEPT_ANYTHING.validate_cbor(encoded_cbor_bytes, True)
In a future release this will become a standalone, more efficient API, see https://gitlab.com/tahoe-lafs/pycddl/-/issues/36
In order to reduce memory usage, you can pass in any Python object that implements the buffer API and stores bytes, e.g. a memoryview() or a mmap object.
The passed-in object must be read-only, and the data must not change during validation! If you mutate the data while validation is happening the result can be memory corruption or other undefined behavior.
If you are deserializing a CBOR document into Python objects, you can deserialize:
Other types will be added in the future if there is user demand.
Schema validation is not restricted to this list, but rather is limited by the functionality of the cddl Rust crate.
Features:
Features:
Features:
Bug fixes:
Features:
validate_cbor(serialized_cbor, True) will deserialize the CBOR document into Python objects, so you don't need to use e.g. cbor2.loads(serialized_cbor) separately.Bug fixes:
Misc:
cddl crate (0.9.4).cddl crate (0.9.3).cddl crate (0.9.2), improving validation functionality.cddl crate, fixing some validation bugs.validate_cbor() now accepts read-only buffers, not just bytes. This is useful if you want to e.g. validate a large file, since you can mmap() it.cddl 0.9.1.Schema() object is created), instead of every time validation happens, which should improve validation performance.repr() implementation to Schema for easier debugging.FAQs
Deserialize CBOR and/or do CDDL schema validation
We found that pycddl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.