Skip to content

Commit cf5a6c5

Browse files
Copilotfzipi
andauthored
ci: add pipeline with upstream libinjection integration (#9)
* Initial plan * Add GitHub Actions CI pipeline for testing with upstream libinjection Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com> * Apply suggestion from @fzipi * Apply suggestions from code review Co-authored-by: Felipe Zipitría <3012076+fzipi@users.noreply.github.com> * Fix pipeline warnings: upgrade actions to Node.js 24, fix undefined symbol for static C functions Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
1 parent 91bd9ef commit cf5a6c5

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
# Run weekly on Mondays at midnight UTC to catch upstream changes
10+
- cron: '0 0 * * 1'
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: ['3.9', '3.10', '3.11', '3.12']
21+
22+
steps:
23+
- uses: actions/checkout@v6
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v6
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Install system dependencies
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y swig gcc python3-dev
34+
35+
- name: Install Python dependencies
36+
run: |
37+
pip install --upgrade pip setuptools pytest
38+
39+
- name: Clone upstream libinjection
40+
run: |
41+
git clone --depth=1 https://github.com/libinjection/libinjection.git upstream
42+
43+
- name: Copy upstream source files
44+
run: |
45+
cp -f upstream/src/libinjection*.h upstream/src/libinjection*.c libinjection/
46+
47+
- name: Create tests symlink for test_driver.py
48+
# test_driver.py resolves test files relative to ../tests from the repo root
49+
run: |
50+
ln -s "$(realpath upstream/tests)" "$(realpath ..)/tests"
51+
52+
- name: Generate words.py from upstream data
53+
run: |
54+
python json2python.py < upstream/src/sqlparse_data.json > words.py
55+
56+
- name: Generate SWIG wrapper
57+
run: |
58+
swig -python -builtin -Wall -Wextra libinjection/libinjection.i
59+
60+
- name: Build C extension in-place
61+
run: |
62+
python setup.py build_ext --inplace
63+
64+
- name: Run tests
65+
run: |
66+
pytest test_driver.py -v

json2python.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def lookup(state, stype, keyword):
2121
keyword = keyword.decode('latin-1')
2222
keyword = keyword.upper()
2323
if stype == libinjection.LOOKUP_FINGERPRINT:
24-
if keyword in fingerprints and libinjection.sqli_not_whitelist(state):
24+
# sqli_check_fingerprint calls sqli_blacklist (fingerprint membership
25+
# check) and sqli_not_whitelist (false-positive reduction) internally.
26+
if libinjection.sqli_check_fingerprint(state):
2527
return 'F'
2628
else:
2729
return chr(0)

libinjection/libinjection.i

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,14 @@ for (i = 0; i < $1_dim0; i++) {
154154
}
155155
%include "libinjection_error.h"
156156
%include "libinjection.h"
157+
158+
// These functions are declared static in the upstream header and therefore
159+
// cannot be exported as symbols from the compiled extension. Ignore them
160+
// so SWIG does not generate wrappers that produce undefined symbol errors
161+
// at import time. Use sqli_check_fingerprint (non-static) instead.
162+
%ignore libinjection_sqli_reset;
163+
%ignore libinjection_sqli_lookup_word;
164+
%ignore libinjection_sqli_blacklist;
165+
%ignore libinjection_sqli_not_whitelist;
157166
%include "libinjection_sqli.h"
158167
%include "libinjection_xss.h"

0 commit comments

Comments
 (0)