mirror of
https://github.com/usememos/memos.git
synced 2026-11-21 03:19:12 +01:00
471745b431
Bound work an anonymous or low-privilege caller can force:
- Bound thumbnail decoding by declared pixel count before decoding and
remember images that cannot be thumbnailed (over the bound or not
decodable), so a small image declaring billions of pixels is served
as-is instead of decoded on every request. Transient storage read
errors are not remembered. The bound lives in internal/imagelimit and
is shared with EXIF stripping.
- Cap request bodies at 16 MiB for procedures that carry no file bytes;
only inline attachment creation, transcription, and chunked uploads
keep their larger caps.
- Digest over-long submitted usernames before using them as sign-in
limiter keys, add header and idle timeouts to the HTTP server, limit
filter expression size, and cap the SQLite regexp cache.
Close correctness gaps:
- Delete the thumbnail the file server actually writes (.v2.jpeg), its
failure marker, and the legacy name when an attachment is removed.
- Decide EXIF stripping from the sniffed content as well as the declared
type, so a mislabeled JPEG keeps no metadata.
- Revoke every other session when a password changes; an admin reset
revokes all of the target's sessions. Prune expired refresh tokens.
- Enforce the 2 MiB avatar limit the web client already applies.
- Keep S3 object keys unique when the path template has no {uuid}.
- Reject negative attachment page tokens.
- Charge memo archive imports against the write and upload budgets,
charge repeated validate-only plans, discard only attachments an
import actually stored, and refuse archives that declare far more
bytes than they hold.
- Load database-stored attachment bytes only after authorization.
- Remove the unused, unguarded linkmeta.GetImage fetcher.
Frontend: send no referrer when loading external images in memos and
link previews, and drop picture/source from the sanitizer so every
remote image goes through the https-only src rule.
Dependencies: grpc 1.83.1 and x/crypto 0.56.0 for reported advisories.
39 lines
958 B
Go
39 lines
958 B
Go
package sqlite
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRegexpFunctionMatches(t *testing.T) {
|
|
require.NoError(t, ensureRegexpRegistered())
|
|
|
|
re, err := compileRegexp(`^v\d+$`)
|
|
require.NoError(t, err)
|
|
require.True(t, re.MatchString("v12"))
|
|
require.False(t, re.MatchString("version"))
|
|
|
|
// Caching returns the same compiled instance.
|
|
re2, err := compileRegexp(`^v\d+$`)
|
|
require.NoError(t, err)
|
|
require.Same(t, re, re2)
|
|
|
|
_, err = compileRegexp(`(`)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestRegexpCacheStaysBounded(t *testing.T) {
|
|
regexpCache.Clear()
|
|
regexpCacheSize.Store(0)
|
|
for i := range maxRegexpCacheEntries * 3 {
|
|
_, err := compileRegexp(fmt.Sprintf(`^pattern-%d$`, i))
|
|
require.NoError(t, err)
|
|
require.LessOrEqual(t, regexpCacheSize.Load(), int64(maxRegexpCacheEntries))
|
|
}
|
|
count := 0
|
|
regexpCache.Range(func(_, _ any) bool { count++; return true })
|
|
require.LessOrEqual(t, count, maxRegexpCacheEntries)
|
|
}
|